Ian Macmillan:
I have this code that I am having a problem with. I would like the stoploss to move every 2 pips instead of ever pip. Can you please help?
You may be lucky and somebody does this for you but you should create an order in freelance section.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
#property copyright "2023, SqueezePlayMA" #include <Trade/Trade.mqh> CTrade trade; ulong trade_ticket = 0; bool time_passed = true; double open_trade_price = 0; input group "SqueezePlayMA"; input group "Open Trade"; input int MovingAverage = 2; input group "Close Trade"; input int HitNumber = 100; input int Movement = 5; input group "Money Management"; input double PercentToRisk = 1.0; double Risk = PercentToRisk / 100; int prev_num_candles = 0; input group "MagicNumber"; input int MagicNumber = 11111; // Magic Number int OnInit() { TesterHideIndicators(true); trade.SetExpertMagicNumber(MagicNumber); return(INIT_SUCCEEDED); } void OnTick() { double Lots = NormalizeDouble(AccountInfoDouble(ACCOUNT_BALANCE)*Risk/HitNumber/(SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE)),2); double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID); static double lastBid = bid; for(int i = PositionsTotal()-1; i >= 0; i--){ ulong posTicket = PositionGetTicket(i); if(PositionSelectByTicket(posTicket)){ double posOpenPrice = PositionGetDouble(POSITION_PRICE_OPEN); double posVolume = PositionGetDouble(POSITION_VOLUME); double posTp = PositionGetDouble(POSITION_TP); double posSl = PositionGetDouble(POSITION_SL); ENUM_POSITION_TYPE posType = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE); if(posType == POSITION_TYPE_BUY){ double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_BID), _Digits); double sl = posSl + Movement * _Point; static double tickCurrent; double tickPrevious = tickCurrent; tickCurrent = Bid; if (tickCurrent > tickPrevious){ Print("Hey new tick buy sl MA"); if(trade.PositionModify(trade_ticket,sl,posTp)){ } } } } } double myMovingAverageArray1[],myMovingAverageArray2[]; int movingAverageDefinition1 = iMA(_Symbol,_Period,1,0,MODE_SMA,PRICE_OPEN); int movingAverageDefinition2 = iMA(_Symbol,_Period,MovingAverage,0,MODE_SMA,PRICE_OPEN); ArraySetAsSeries(myMovingAverageArray1,true); ArraySetAsSeries(myMovingAverageArray2,true); CopyBuffer(movingAverageDefinition1,0,0,3,myMovingAverageArray1); CopyBuffer(movingAverageDefinition2,0,0,3,myMovingAverageArray2); uchar Position_Count = 0; for(int i=PositionsTotal()-1; i>=0; i--) { ulong Position_Magic_Number = PositionGetInteger(POSITION_MAGIC); if(Position_Magic_Number == MagicNumber) Position_Count+=1; } if(Position_Count < 1) if ((myMovingAverageArray1[0]>myMovingAverageArray2[0]) && (myMovingAverageArray1[1]<myMovingAverageArray2[1])&& time_passed == true){ double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_ASK), _Digits); open_trade_price = Ask; double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_BID), _Digits); open_trade_price = Bid; trade.Buy(Lots, _Symbol, Ask, Bid-HitNumber*_Point, Ask+HitNumber*_Point, "SqueezePlayMA Buy"); trade_ticket = trade.ResultOrder(); } for(int i=PositionsTotal()-1; i>=0; i--) { ulong Position_Magic_Number = PositionGetInteger(POSITION_MAGIC); if(Position_Magic_Number == MagicNumber) Position_Count+=1; } if(Position_Count < 1) if ((myMovingAverageArray1[0]<myMovingAverageArray2[0]) && (myMovingAverageArray1[1]>myMovingAverageArray2[1])&& time_passed == true){ double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_BID), _Digits); open_trade_price = Bid; double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_ASK), _Digits); trade.Sell(Lots, _Symbol, Bid, Ask+HitNumber*_Point, Bid-HitNumber*_Point, "SqueezePlayMA Buy"); trade_ticket = trade.ResultOrder(); } }