Virtual_SL_TP

Author: Copyright © 2017, cmillion@narod.ru
Orders Execution
Checks for the total of open ordersIt Closes Orders by itself It automatically opens orders when conditions are reached
0 Views
0 Downloads
0 Favorites
Virtual_SL_TP
ÿþ//+------------------------------------------------------------------+

#property copyright "Copyright © 2017, cmillion@narod.ru"

#property link      "http://cmillion.ru"

#property strict

#property description "!>25B=8: 2KAB02;O5B AB>?;>A 8 B59:?@>D8B =52848<K5 4;O 1@>:5@0"

//--------------------------------------------------------------------

input int     Stoploss      = 100;    //AB>?;>AA (0->B:;)

input int     Takeprofit    = 50;     //B59:?@>D8B (0->B:;)

input int     slippage=30;

//--------------------------------------------------------------------

void OnTick()

{      

   double OOP;

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

   {    

      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

      { 

         if (OrderSymbol()==Symbol())

         { 

            int tip = OrderType(); 

            OOP = NormalizeDouble(OrderOpenPrice(),Digits);

            if (tip==OP_BUY)             

            {  

               if (Stoploss!=0   && Bid<=OOP - Stoploss   * Point) {if (OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),slippage,clrNONE)) continue;}

               if (Takeprofit!=0 && Bid>=OOP + Takeprofit * Point) {if (OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),slippage,clrNONE)) continue;}

            }                                         

            if (tip==OP_SELL)        

            {  

               if (Stoploss!=0   && Ask>=OOP + Stoploss   * Point) {if (OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),slippage,clrNONE)) continue;}

               if (Takeprofit!=0 && Ask<=OOP - Takeprofit * Point) {if (OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),slippage,clrNONE)) continue;}

            } 

         }

      }

   } 

   //---

   int err;

   if (IsTesting() && OrdersTotal()==0)

   {

      double Lot=0.1;

      err=OrderSend(Symbol(),OP_BUY,Lot,NormalizeDouble(Ask,Digits),slippage,0,0,"B5AB",0);

      err=OrderSend(Symbol(),OP_SELL,Lot,NormalizeDouble(Bid,Digits),slippage,0,0,"B5AB",0);

      return;

   }

}

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

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 ---