I need help with my timebased-trading

 

Hello Guys,


I want a algorithm which trades periods of time.

It should open a Trade on every 26th of a month except on January&Juli.

And close this Trade on every 5th Month of next.

with no Stoploss.


I came so far..

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

#include<Trade\Trade.mqh>
 
CTrade trade;
 
void OnTick()
  {

double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);

datetime zeit=CALENDAR_TIMEMODE_DATE();

string Datum=TimeToString(zeit, ORDER_TIME_DAY);
if((PositionsTotal()==0)&(StringSubstr(Datum,0,30)=="26"))

   {
   trade.Buy(0.10,NULL,Ask,0,(StringSubstr(Datum,0,30)=="5"),NULL);
   }   

  
   Comment (Datum);
  }
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Requests to execute trade operations are formalized as orders. Each order has a variety of properties for reading. Information on them can be obtained using functions Position identifier that is set to an order as soon as it is executed. Each executed order results in a deal that opens or modifies an already existing position. The identifier of...
 
Please edit your post and
use the code button (Alt+S) when pasting code
 

Now im this far...


#include<Trade\Trade.mqh>
#include <Trade\PositionInfo.mqh>
 
CTrade trade;
CPositionInfo  m_position;
 
void OnTick()
  {

double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);

MqlDateTime date;

datetime date1= D'2019.26.02';
datetime date2= D'2019.26.03';
datetime date3= D'2019.26.04';
datetime date4= D'2019.26.05';
datetime date5= D'2019.26.06';
datetime date6= D'2019.26.08';


datetime date8= D'2019.05.03';
datetime date9= D'2019.05.04';
datetime date10= D'2019.05.05';
datetime date11= D'2019.05.06';
datetime date12= D'2019.05.08';

datetime now = TimeCurrent();



if((PositionsTotal()==0) && now == date1 || date2 || date3 || date4 || date5 || date6 ) 

   {
   trade.Buy(0.10,NULL,Ask,0,0,NULL);
   }   

 if((PositionsTotal()==1) && now == date11 || date12 || date10 || date9 || date8 ) 

   {
   trade.PositionClose(1);
   }   
   
  }
//+------------------------------------------------------------------+