SelectTrade

Author: genino.belaev@yandex.ru
Orders Execution
It automatically opens orders when conditions are reachedChecks for the total of open orders
0 Views
0 Downloads
0 Favorites
SelectTrade
ÿþ//+------------------------------------------------------------------+

//|                                                  SelectTrade.mq4 |

//|                                  Copyright 2017, Evgeny Belyaev  |

//|                                  email: genino.belaev@yandex.ru  |

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

#property copyright "genino.belaev@yandex.ru"

#property link      "genino.belaev@yandex.ru"

#property version   "1.00"

#property strict

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

//|                                                                  |

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

enum select

  {

   BUY=0,

   SELL=1

  };

input select Trade=BUY;

input double lots=0.1;

extern int TakeProfit=20;

extern int StopLoss=50;

input int magic=57296;

input int Slippage=20;

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

//| Expert initialization function                                   |

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

int OnInit()

  {

   if(Digits==5 || Digits==3)

     {

      TakeProfit  *=10;

      StopLoss    *=10;

     }

   return(INIT_SUCCEEDED);

  }

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

//| Expert deinitialization function                                 |

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

void OnDeinit(const int reason)

  {





  }

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

//| Expert tick function                                             |

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

void OnTick()

  {

   if(Count()==0)

     {

      if(Trade==BUY)

        {

         OPENORDER_BUY();

        }

      else

        {

         OPENORDER_Sell();

        }

     }

     Comment("!2O70BLAO A @07@01>BG8:>< <>6=> ?> ?>GB5 genino.belaev@yandex.ru");

  }

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

void OPENORDER_BUY()

  {



   int error;

   double SL=0,TP=0;

     {

      if(TakeProfit!=0) TP=NormalizeDouble(Ask+TakeProfit*Point,Digits); else TP=0;

      if(StopLoss!=0)SL=NormalizeDouble(Ask-StopLoss*Point,Digits);   else SL=0;

      error=OrderSend(Symbol(),OP_BUY,lots,Ask,Slippage,SL,TP,"?>:C?:0",magic,0,clrGreen);

     }



  }

//////////////////////////////////////////////////////////////////////////////////////////////

void OPENORDER_Sell()

  {



   int error;

   double SL=0,TP=0;



     {

      if(TakeProfit!=0) TP=NormalizeDouble(Bid-TakeProfit*Point,Digits); else TP=0;

      if(StopLoss!=0)SL=NormalizeDouble(Bid+StopLoss*Point,Digits);   else SL=0;

      error=OrderSend(Symbol(),OP_SELL,lots,Bid,Slippage,SL,TP,"?@>4060",magic,0,clrRed);

     }

  }

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

int Count()

  {

   int count=0;

   int i;

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

     {

      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

        {

         if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && (OrderType()==OP_BUY || OrderType()==OP_SELL))

            count++;

        }

     }

   return(count);

  }

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

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