/ / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +  
 / / |                                                                                                             P r o j e c t N a m e   |  
 / / |                                                                             C o p y r i g h t   2 0 1 8 ,   C o m p a n y N a m e   |  
 / / |                                                                               h t t p : / / w w w . c o m p a n y n a m e . n e t   |  
 / / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +  
 # i n c l u d e   < s t d l i b . m q h >  
 # i n c l u d e   < s t d e r r o r . m q h >  
 # i n c l u d e   < . . \ E x p e r t s \ I n c l u d e s \ K o b _ 4 . m q 4 >  
  
  
 / / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +  
 / / |                                                     C o n f i g u r a t i o n                                                       |  
 / / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +  
  
 i n p u t   i n t   B G C o l o u r s   =   1 ;   / /   2 0 "   f o r   n o   b a c k g r o u n d   c o l o u r s  
 i n p u t   c o l o r   S h o r t C o l o u r   =   c l r M a r o o n ;  
 i n p u t   c o l o r   L o n g C o l o u r   =   c l r N a v y ;  
 i n p u t   c o l o r   H e d g e C o l o u r   =   c l r F i r e B r i c k ;  
 i n p u t   c o l o r   S i g n a l C o l o u r   =   c l r S t e e l B l u e ;  
 i n p u t   c o l o r   N o C o l o u r   =   c l r B l a c k ;  
 e x t e r n   b o o l   E n a b l e A l e r t   =   t r u e ;  
 e x t e r n   b o o l   E n a b l e N o t i f i c a t i o n   =   t r u e ;  
  
  
 d o u b l e   C l o s e O l d ;                                         / /   U s e d   t o   i d e n t i f y   a   n e w   b a r   i n   t h e   c o d e .  
 i n t   L o n g p o s i t i o n ,   S h o r t p o s i t i o n ;         / /   T e l l s   i f   t h e   i n s t r u m e n t   i s   o w n e d .  
 i n t   T r a d e U p ,   T r a d e D o w n ;                           / /   L o n g   e l l e r   S h o r t ?  
 s t r i n g   B a g g r u n d ;  
 i n t   i ;  
 i n t   D a t o ,   D a t o O l d ,   D a g s l u k ;  
 i n t   S i g n a l ;  
  
 / / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +  
 / / |                                             T e k s t   o n   t h e   S c r e e n                                                   |  
 / / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +  
 v o i d   T e k s t S c r e e n ( s t r i n g   T e k s t )  
     {  
       i n t   N u m m e r   =   r a n d ( ) ;  
       s t r i n g   N a m e   =   ( N u m m e r ) ;  
     }  
  
 / / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +  
 / / |                                                     I n i t                                                                         |  
 / / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +  
 i n t   O n I n i t ( )  
     {  
       r e t u r n ( I N I T _ S U C C E E D E D ) ;  
     }  
 / / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +  
 / / |                                                     S t a r t                                                                       |  
 / / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +  
 i n t   s t a r t ( )  
     {  
       l o n g   T F   =   C h a r t P e r i o d ( 0 ) ;  
  
 / /   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *  
 / /   F r o m   h e r e   t h e   c o d e   i s   v i s i t e d   o n l y   a t   e v e r y   n e w   b a r .  
       i f ( C l o s e [ 1 ]   ! =   C l o s e O l d ) / /   D e r v e d   k ø r e r   s c r i p t e t   k u n   é n   g a n g   p e r   b r i c k  
           {  
             C l o s e O l d   =   C l o s e [ 1 ] ;   / / E n   n y   b a r   f o r e k o m m e r .  
  
  
             / / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +  
             / / |                                                       D a t a                                                                       |  
             / / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +  
  
             d o u b l e   S M A 5   =   i M A ( N U L L ,   0 ,   5 ,   0 ,   M O D E _ S M A ,   P R I C E _ C L O S E ,   1 ) ;  
             d o u b l e   S M A 5 O L D   =   i M A ( N U L L ,   0 ,   5 ,   0 ,   M O D E _ S M A ,   P R I C E _ C L O S E ,   2 ) ;  
             d o u b l e   E M A 5 0   =   i M A ( N U L L ,   0 ,   5 0 ,   0 ,   M O D E _ E M A ,   P R I C E _ C L O S E ,   1 ) ;  
             d o u b l e   E M A 5 0 O L D   =   i M A ( N U L L ,   0 ,   5 0 ,   0 ,   M O D E _ E M A ,   P R I C E _ C L O S E ,   2 ) ;  
             d o u b l e   R S I V a l u e   =   M a t h C e i l ( i R S I ( N U L L ,   0 ,   1 4 ,   0 ,   0 ) ) ;  
             d o u b l e   B o l l i n g e r U P   =   i B a n d s ( N U L L , 0 , 2 0 , 2 , 0 , P R I C E _ C L O S E , M O D E _ U P P E R , 0 ) ;  
             d o u b l e   B o l l i n g e r D o w n   =   i B a n d s ( N U L L , 0 , 2 0 , 2 , 0 , P R I C E _ C L O S E , M O D E _ L O W E R , 0 ) ;  
             d o u b l e   B o l l i n g e r 2 0   =   i B a n d s ( N U L L , 0 , 2 0 , 2 , 0 , P R I C E _ C L O S E , M O D E _ M A I N , 0 ) ;  
  
  
             / / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +  
             / / |                                                 S i g n a l s                                                                       |  
             / / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +  
             i n t   i   =   5 ;  
             i n t   D o w n S i g n a l L o a d e d   =   0 ;  
             i n t   U p S i g n a l L o a d e d   =   0 ;  
             i n t   C l e a r C r o s s   =   0 ;  
             S i g n a l   =   0 ;  
  
             w h i l e ( i   > =   0 )  
                 {  
                   i f ( C l o s e [ i ]   > =   i B a n d s ( N U L L , 0 , 2 0 , 2 , 0 , P R I C E _ C L O S E , M O D E _ U P P E R , i ) )  
                         D o w n S i g n a l L o a d e d   =   1 ;  
                   i f ( C l o s e [ i ]   < =   i B a n d s ( N U L L , 0 , 2 0 , 2 , 0 , P R I C E _ C L O S E , M O D E _ L O W E R , i ) )  
                         U p S i g n a l L o a d e d   =   1 ;  
                   i = i - 1 ;  
                 }  
  
             s t r i n g   P a r   =   " s t r i n g _ S y m b o l " ;  
  
             i f ( C l e a r C r o s s   = =   0 )  
                 {  
  
                   i f ( C l o s e [ 1 ]   < =   E M A 5 0   & &   H i g h [ 2 ]   > =   E M A 5 0 O L D   & &   L o w [ 1 ]   >   B o l l i n g e r D o w n   & &   D o w n S i g n a l L o a d e d   = =   1 )  
                       {  
                         S i g n a l   =   - 1 ;  
                         i f ( E n a b l e A l e r t   = =   t r u e )  
                               A l e r t ( S y m b o l ( ) ,   "       B M A   S i g n a l   B a r   c r o s s   d o w n   E M A 5 0 " ) ;  
                         i f ( E n a b l e N o t i f i c a t i o n   = =   t r u e )  
                               S e n d N o t i f i c a t i o n ( " B M A   S h o r t   S i g n a l .       " +   S y m b o l ( ) +   "       T i m e F r a m e   " +   T F ) ;  
                       }  
  
                   i f ( C l o s e [ 1 ]   > =   E M A 5 0   & &   L o w [ 2 ]   < =   E M A 5 0 O L D   & &   H i g h [ 1 ]   <   B o l l i n g e r U P   & &   U p S i g n a l L o a d e d   = =   1 )  
                       {  
                         S i g n a l   =   1 ;  
                         i f ( E n a b l e A l e r t   = =   t r u e )  
                               A l e r t ( S y m b o l ( ) ,   "       B M A   S i g n a l   B a r   c r o s s   u p   E M A 5 0 " ) ;  
                         i f ( E n a b l e N o t i f i c a t i o n   = =   t r u e )  
                               S e n d N o t i f i c a t i o n ( " B M A   L o n g   S i g n a l .       " +   S y m b o l ( ) +   "       T i m e F r a m e   " +   T F ) ;  
                       }  
                 }  
  
           }   / / i f ( C l o s e [ 1 ]   ! =   C l o s e O l d )   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *  
  
  
 / / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +  
 / / |                                                   B a c k g r o u n d   c o l o u r s                                               |  
 / / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +  
       L o n g p o s i t i o n   =   0 ;  
       S h o r t p o s i t i o n   =   0 ;  
  
  
       f o r ( i   =   O r d e r s T o t a l ( )   -   1 ;   i   > =   0 ;   i - - )  
           {  
             O r d e r S e l e c t ( i ,   S E L E C T _ B Y _ P O S ,   M O D E _ T R A D E S ) ;  
  
             i f ( O r d e r S y m b o l ( )   = =   S y m b o l ( ) )  
                 {  
                   / / E j e s   L o n g .  
                   i f ( O r d e r T y p e ( )   = =   O P _ B U Y )  
                       {  
                         L o n g p o s i t i o n   =   L o n g p o s i t i o n   +   1 ;  
                       }  
  
                   / / E j e s   S h o r t .  
                   i f ( O r d e r T y p e ( )   = =   O P _ S E L L )  
                       {  
                         S h o r t p o s i t i o n   =   S h o r t p o s i t i o n   +   1 ;  
                       }  
  
                 }  
           }  
  
       i f ( B G C o l o u r s   = =   1 )  
           {  
             i f ( D a g s l u k   = =   0 )  
                 {  
                   i f ( L o n g p o s i t i o n   = =   0   & &   S h o r t p o s i t i o n   = =   0 )  
                         C h a r t S e t I n t e g e r ( C h a r t I D ( ) ,   C H A R T _ C O L O R _ B A C K G R O U N D ,   N o C o l o u r ) ;         / /   N o t   u s e d .  
                   i f ( L o n g p o s i t i o n   > =   1   & &   S h o r t p o s i t i o n   = =   0 )  
                         C h a r t S e t I n t e g e r ( C h a r t I D ( ) ,   C H A R T _ C O L O R _ B A C K G R O U N D ,   L o n g C o l o u r ) ;           / /   O w n e d   L o n g .  
                   i f ( L o n g p o s i t i o n   = =   0   & &   S h o r t p o s i t i o n   > =   1 )  
                         C h a r t S e t I n t e g e r ( C h a r t I D ( ) ,   C H A R T _ C O L O R _ B A C K G R O U N D ,   S h o r t C o l o u r ) ;       / /   O w n e d   S h o r t .  
                   i f ( L o n g p o s i t i o n   = =   1   & &   S h o r t p o s i t i o n   = =   1 )  
                         C h a r t S e t I n t e g e r ( C h a r t I D ( ) ,   C H A R T _ C O L O R _ B A C K G R O U N D ,   H e d g e C o l o u r ) ; / /   O w n e d   i n   b o t h   d i r e c t i o n s .  
                   i f ( S i g n a l   = =   1   | |   S i g n a l   = =   - 1 )  
                         C h a r t S e t I n t e g e r ( C h a r t I D ( ) ,   C H A R T _ C O L O R _ B A C K G R O U N D ,   S i g n a l C o l o u r ) ; / /   O w n e d   i n   b o t h   d i r e c t i o n s .  
                 }  
             i f ( D a g s l u k   = =   1 )  
                   C h a r t S e t I n t e g e r ( C h a r t I D ( ) ,   C H A R T _ C O L O R _ B A C K G R O U N D ,   c l r C o r n f l o w e r B l u e ) ;  
           }  
  
  
 / / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +  
 / / |                                                   W r i t e   s p l i t   o n   s c r e e n                                         |  
 / / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +  
       s t r i n g   S p l i t ,   S p l i t 2 ;  
  
       S p l i t   =   " S p l i t t " ;  
       S p l i t 2   =   " S p l i t t 2 " ;  
  
       d o u b l e   S p l i t V a l u e   =   N o r m a l i z e D o u b l e ( ( A s k   -   B i d )   /   P o i n t   /   1 0 ,   2 ) ;  
  
       O b j e c t D e l e t e ( " S p l i t t " ) ;  
       O b j e c t C r e a t e ( " S p l i t t " ,   O B J _ L A B E L ,   0 ,   0 ,   0 ) ;  
       O b j e c t S e t T e x t ( " S p l i t t " , " S p l i t " ,   1 2 ,   " V e r d a n a " ,   W h i t e ) ;  
       O b j e c t S e t ( " S p l i t t " ,   O B J P R O P _ C O R N E R ,   C O R N E R _ R I G H T _ U P P E R ) ;  
       O b j e c t S e t ( " S p l i t t " ,   O B J P R O P _ X D I S T A N C E , 1 0 0 ) ;  
       O b j e c t S e t ( " S p l i t t " ,   O B J P R O P _ Y D I S T A N C E , 2 0 ) ;  
  
       O b j e c t D e l e t e ( " S p l i t t 2 " ) ;  
       O b j e c t C r e a t e ( " S p l i t t 2 " ,   O B J _ L A B E L ,   0 ,   0 ,   0 ) ;  
       O b j e c t S e t T e x t ( " S p l i t t 2 " , S p l i t V a l u e , 1 2 ,   " V e r d a n a " ,   Y e l l o w ) ;  
       O b j e c t S e t ( " S p l i t t 2 " ,   O B J P R O P _ C O R N E R ,   C O R N E R _ R I G H T _ U P P E R ) ;  
       O b j e c t S e t ( " S p l i t t 2 " ,   O B J P R O P _ X D I S T A N C E , 2 5 ) ;  
       O b j e c t S e t ( " S p l i t t 2 " ,   O B J P R O P _ Y D I S T A N C E , 2 0 ) ;  
  
     }  
 / / + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +  
 