cm ReopeningAfterProfit

Author: Copyright © 2019, Vladimir Hlystov
Orders Execution
Checks for the total of closed ordersChecks for the total of open ordersIt automatically opens orders when conditions are reached
0 Views
0 Downloads
0 Favorites
cm ReopeningAfterProfit
ÿþ//+------------------------------------------------------------------+

//|                               Copyright © 2014, Vladimir Hlystov |

//|                                                cmillion@narod.ru |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2019, Vladimir Hlystov"

#property link      "cmillion@narod.ru"

#property strict

#property description "!>25B=8: >B:@K205B ;8<8B=K9 >@45@ =0 <5AB5 B>;L:> GB> 70:@KB>3> ?@81K;L=>3> >@45@0"

#property description "A5 ?0@0<5B@K, ;>B AB>?;>AA, B59:?@>D8B 8 =0?@02;5=85 845=B8G=K 70:@KB><C"

#property description "@8<5@ @01>BK"

#property description "B@KB0 ?>78F8O 1,1234 ?>A;5 55 70:@KB8O ?> ?@>D8BC =0 F5=C 1,1234 2AB0=5B ;8<8B=K9 >@45@ A B5<8 65 ?0@0<5B@0<8. A;8 ?>78F8O 70:@>5BAO 2 C1KB>:, B> 40;55 >@45@0 >B:@K20BL A>25B=8: =5 1C45B."

#property description " B5AB5@5 A>25B=8: >B:@K205B 420 >@45@0 buy 8 sell 4;O B>3>, GB>1K <>6=> 1K;> =03;O4=> C2845BL 53> @01>BC."

//+------------------------------------------------------------------+

void OnTick()

{

   double OOP=0,OTP=0,OSL=0,OL=0;

   int i,OT=0;

   for (i=OrdersHistoryTotal()-1; i>=0; i--)

   {  

      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))

      {      

         OT=OrderType();

         if (OT<2)

         {

            if (OrderProfit()>0)

            {

               OTP = NormalizeDouble(OrderTakeProfit(),Digits);

               OOP = NormalizeDouble(OrderOpenPrice(),Digits);

               OSL = NormalizeDouble(OrderStopLoss(),Digits);

               OL  = OrderLots();

            }

            else OOP=0;

            break;

         }

      }  

   }

   if (OOP!=0)

   {

      for (i=0; i<OrdersTotal(); i++)

      {  

         if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

         {  

            if (OrderSymbol()==Symbol())

            {

               if (NormalizeDouble(OrderOpenPrice(),Digits) == OOP && OL == OrderLots()) return;

            }  

         }  

      }

      if (OT==OP_BUY) OT=OP_BUYLIMIT;

      if (OT==OP_SELL) OT=OP_SELLLIMIT;

      if (OrderSend(Symbol(),OT,OL,OOP,0,OSL,OTP,NULL,0,0,clrNONE)==-1) Print("Error ",GetLastError()," Type=",OT," Price=",OOP," SL=",OSL," TP=",OTP);

   }

   else

   {

      Comment(">A;54=89 >@45@ 70:@KB A C1KB:><, limit >@45@ =5 AB028<");

      if (IsTesting())

      {

         int b=0,s=0;

         for (i=0; i<OrdersTotal(); i++)

         {  

            if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

            {  

               if (OrderSymbol()==Symbol())

               {

                  OT=OrderType();

                  if (OT==OP_BUY) b++;

                  if (OT==OP_SELL) s++;

               }  

            }  

         }

         if (b==0) if (OrderSend(Symbol(),OP_BUY ,0.1,Ask,10,Ask-100*Point,Ask+15*Point,NULL,0,0,clrLime)==-1) Print("Error");

         if (s==0) if (OrderSend(Symbol(),OP_SELL,0.1,Bid,10,Bid+100*Point,Bid-15*Point,NULL,0,0,clrRed)==-1) Print("Error");

      }

   }

}

//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---