//buy below the open //sell above the open #include #include //struct tfCoord // { // ENUM_TIMEFRAMES xtf; // ENUM_TIMEFRAMES ytf; // ENUM_TIMEFRAMES ztf; // }; // //tfCoord tf; input double BEFactor; //multiple of rr, that will acticate lock-in //Timeframe Coordination input ENUM_TIMEFRAMES InpXtf; //main starting tf input ENUM_TIMEFRAMES inpYtf; // middle linking tf input ENUM_TIMEFRAMES inpZtf; //execution tf input double inpLot; //preferred position size double FixedSizeRisk; input int inpTickClearance; // number of ticks allowed to go beyond pre-defined sl input int inpRR; //Risk to reward ratio; input bool inpTrigger1; //activate recieval of triggering signal from model1 extern bool trigger(); //other complex logic //Globals bool isAbove; bool isBelow; double lockIn; //this for every open position //int beyond; //-1 for below, 1 for above bool isNewCandle; bool isTradeDay; int signalFlag; static bool hasFired = false; int buyCounts; int sellCounts; //ENUM_TIMEFRAMES tf {PERIOD_H1, PERIOD_M5, PERIOD_M1}; struct rates{ ENUM_TIMEFRAMES tf; int beyond; MqlRates x[]; // int triggerFlag; //potential buy/sell catalyst }; rates r[3]; //can instanciate rates object to look for other potential signal from another TF CTrade trade; CSymbolInfo symInfo; //Forward declaration void breakEven(); bool trigger(int &flag, int tfIndex, int candleIndex); //a reason to act bool IsNewCandle() { static datetime lastTime = 0; datetime currentTime = iTime(_Symbol, inpZtf, 0); if(lastTime != currentTime) { lastTime = currentTime; return true; } return false; } int OnInit(void) { //initiate vars signalFlag=0; //Validating user input var if((InpXtfr[i].x[0].open){ //current price trading above the opening r[i].beyond=1; } else if(r[i].x[0].closer.x[0].open){ //current price trading above the opening // beyond=1; // } // else if(r.x[0].close=0;--i){ ulong ticket = PositionGetTicket(i); if(ticket > 0 && PositionGetString(POSITION_SYMBOL) == _Symbol) { double sl=PositionGetDouble(POSITION_SL); double tp=PositionGetDouble(POSITION_TP); double entryPrice=PositionGetDouble(POSITION_PRICE_OPEN); double risk=MathAbs(entryPrice-sl); int posType = (int)PositionGetInteger(POSITION_TYPE); double BEPoint=factor*risk; double newSL=0; // Calculate lock-in price based on position type if(posType==POSITION_TYPE_BUY){ lockIn=entryPrice+BEPoint; } else if(posType==POSITION_TYPE_SELL){ lockIn=entryPrice-BEPoint; } // Check if price has crossed the lock-in threshold if(r[0].x[0].high>lockIn && r[0].x[0].lowsl) || (posType==POSITION_TYPE_SELL && newSLr[tfIndex].x[candleIndex+1].high){ // //bullish catalyst // flag=1; // return true; // } // else if(r[tfIndex].x[candleIndex].closelower//bearish momentum candle &&(r[tfIndex].x[candleIndex].low>r[tfIndex].x[candleIndex+1].low)){ //bearish catalyst flag=-1; return true; } if(lower>upper//bullish momentum candle &&(r[tfIndex].x[candleIndex].high