//+------------------------------------------------------------------+ //| Scalper Insider Bot.mq4 | //| Copyright 2024, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2024, MetaQuotes Ltd." #property link "https://www.mql5.com" #property version "1.00" #property strict enum trade { buy, sell, both }; enum Tp { Tp1, Tp2, Tp3 }; enum closeBrilliant { Big,//Big Medium, //Medium Bothx,//Both }; input trade Trade_direction=both;//Trade Direction input bool Enable_Tp=true; input Tp SelectTpLevel=Tp1; input double CloseTradesOnPips=10; enum type { Fixed, Dynamic }; input type LotSizeType=Fixed; input double risk=1; //Risk % input double LotSize=0.01; input bool CloseReversal=false; input string _="Trade Close"; input bool EnableBrilliant=false; input bool ProfitCheckBrilliant=false; input int LuckyReversalRangeCandles=5; //BrilliantReversalRangeCandles input closeBrilliant SelectBrilliant=Bothx; input bool EnableOnProfit=true; input int CloseAfterHour=1; input double MaxLossPips=20; input double StopLoss=0; input double TakeProfit=0; input bool UseTrailing=true; input int TrailingStop = 50; // Trailing Stop input int Profit = 100; // Profit in points when TS should kick in. input bool UseSpread=true; input int MaxSpread=15; datetime BrillaintTimeBuy; datetime BrillaintTimeSell; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ datetime BuyTime,SellTime; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnTick() { if(nbuy(123)==0) { BuyTime=NULL; } if(nsell(123)==0) { SellTime=NULL; } if(CloseAfterHour!=0) { // if(nsell(123)>0) { if(Time[0]>SellTime+CloseAfterHour*PeriodSeconds(PERIOD_H1)) { if(MaxLossPips!=0) { if(MaxLossPips!=0 && MathAbs(fso(123)-Ask)/GetPipPoint()< MaxLossPips) { CloseSell(123); } } else { CloseSell(123); } } } // if(nbuy(123)>0) { if(Time[0]>BuyTime+CloseAfterHour*PeriodSeconds(PERIOD_H1)) { if(MaxLossPips!=0) { if(MaxLossPips!=0 && MathAbs(fbo(123)-Bid)/GetPipPoint()< MaxLossPips) { CloseBuy(123); } } else { CloseBuy(123); } } } } if(CloseTradesOnPips!=0) { if(CloseTradesOnPips!=0 && Askfbo(123)+CloseTradesOnPips*GetPipPoint()) { CloseBuy(123); } } double bigBuy=iCustom(_Symbol,PERIOD_CURRENT,"brilliant-reversals-indicator",4,1); double mediumBuy=iCustom(_Symbol,PERIOD_CURRENT,"brilliant-reversals-indicator",2,1); double bigSell=iCustom(_Symbol,PERIOD_CURRENT,"brilliant-reversals-indicator",5,1); double mediumSell=iCustom(_Symbol,PERIOD_CURRENT,"brilliant-reversals-indicator",3,1); if(SelectBrilliant==Big) { if(bigBuy!=0) { BrillaintTimeBuy=Time[1]; if(NS(123)>0 ||!EnableBrilliant) { if(ProfitCheckBrilliant) { CloseSell(123); } } } } else if(SelectBrilliant==Medium) { if(mediumBuy!=0) { if(EnableBrilliant) { if(NS(123)>0 ||!EnableBrilliant) { CloseSell(123); } } BrillaintTimeBuy=Time[1]; } } else if(SelectBrilliant==Bothx) { if(bigBuy!=0 || mediumBuy!=0) { if(EnableBrilliant) { if(NS(123)>0 ||!EnableBrilliant) { CloseSell(123); } } BrillaintTimeBuy=Time[1]; } } //--- // if(SelectBrilliant==Big) { if(bigSell!=0) { BrillaintTimeSell=Time[1]; if(EnableBrilliant) { if(NB(123)>0 ||!EnableBrilliant) { CloseBuy(123); } } } } else if(SelectBrilliant==Medium) { if(mediumSell!=0) { if(EnableBrilliant) { if(NB(123)>0 || !EnableBrilliant) { CloseBuy(123); } } BrillaintTimeSell=Time[1]; } } else if(SelectBrilliant==Bothx) { if(bigSell!=0 || mediumSell!=0) { if(EnableBrilliant) { if(NB(123)>0 ||!EnableBrilliant) { CloseBuy(123); } } BrillaintTimeSell=Time[1]; } } double buy=iCustom(_Symbol,PERIOD_CURRENT,"Market\Scalper Inside PRO",0,1); double sell=iCustom(_Symbol,PERIOD_CURRENT,"Market\Scalper Inside PRO",1,1); if(buy!=2147483647 && (MarketInfo(_Symbol,MODE_SPREAD)<=MaxSpread || !UseSpread)) { if(Trade_direction==buy || Trade_direction==both) { if(nbuy(123)==0 && nsell(123)==0) { double tp; if(TakeProfit<=0 && Enable_Tp) { if(SelectTpLevel==Tp1) { tp=iCustom(_Symbol,PERIOD_CURRENT,"Market\Scalper Inside PRO",3,1); } else if(SelectTpLevel==Tp2) { tp=iCustom(_Symbol,PERIOD_CURRENT,"Market\Scalper Inside PRO",4,1); } else if(SelectTpLevel==Tp3) { tp=iCustom(_Symbol,PERIOD_CURRENT,"Market\Scalper Inside PRO",5,1); } } else { tp=Ask+TakeProfit*GetPipPoint(); } if(CloseReversal) { CloseSell(123); } if(Bars(_Symbol,PERIOD_CURRENT,BrillaintTimeSell,Time[1])>=LuckyReversalRangeCandles) { double lot; if(LotSizeType==Fixed) { lot=LotSize; } else { lot=GetLots(); } int ticket= OrderSend(_Symbol,OP_BUY,lot,Ask,100,StopLoss>0?Ask-StopLoss*GetPipPoint():0,tp,0,123); if(ticket>0) { BuyTime=Time[0]; } } } } } // if(sell!=2147483647 && (MarketInfo(_Symbol,MODE_SPREAD)<=MaxSpread || !UseSpread)) { if(Trade_direction==sell || Trade_direction==both) { if(nbuy(123)==0 && nsell(123)==0) { double tp; if(TakeProfit<=0 && Enable_Tp) { if(SelectTpLevel==Tp1) { tp=iCustom(_Symbol,PERIOD_CURRENT,"Market\Scalper Inside PRO",3,1); } else if(SelectTpLevel==Tp2) { tp=iCustom(_Symbol,PERIOD_CURRENT,"Market\Scalper Inside PRO",4,1); } else if(SelectTpLevel==Tp3) { tp=iCustom(_Symbol,PERIOD_CURRENT,"Market\Scalper Inside PRO",5,1); } } else { tp=Bid-TakeProfit*GetPipPoint(); } if(CloseReversal) { CloseBuy(123); } if(Bars(_Symbol,PERIOD_CURRENT,BrillaintTimeBuy,Time[1])>=LuckyReversalRangeCandles) { double lot; if(LotSizeType==Fixed) { lot=LotSize; } else { lot=GetLots(); } int ticket= OrderSend(_Symbol,OP_SELL,lot,Bid,100,StopLoss>0?Bid+StopLoss*GetPipPoint():0,tp,0,123); if(ticket>0) { SellTime=Time[0]; } } } } } } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ double GetPipPoint(const string argSymbol=NULL) { int CalcDigits =SymbolInfoInteger(argSymbol,SYMBOL_DIGITS); if(CalcDigits == 2 || CalcDigits == 3) return 0.01; if(CalcDigits == 1 || CalcDigits == 0) return 1; // else if (CalcDigits == 4 || CalcDigits == 5) return 0.0001; } //+------------------------------------------------------------------+ void CloseBuy(int m) { for(int i=0; i0) CloseBuy(m); } //////////////////////////////////////// void CloseSell(int m) { for(int i=0; i0) CloseSell(m); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int nbuy(int m) { int buy=0; for(int i=0; i= 0; i--) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false) { int Error = GetLastError(); Print("ERROR - Unable to select the order - ", Error); // Print("ERROR - ", ErrorText); break; } if((OrderSymbol() != Symbol())) continue; int eDigits = (int)MarketInfo(OrderSymbol(), MODE_DIGITS); //double point = MarketInfo(OrderSymbol(), MODE_POINT); double ask = SymbolInfoDouble(OrderSymbol(), SYMBOL_ASK); double bid = SymbolInfoDouble(OrderSymbol(), SYMBOL_BID); double TickSize = SymbolInfoDouble(OrderSymbol(), SYMBOL_TRADE_TICK_SIZE); // Normalize trailing stop value to the point value. double TSTP = TrailingStop*GetPipPoint(_Symbol) ; double P = Profit*GetPipPoint(_Symbol); if(OrderType() == OP_BUY) { //from order Open if(OrderStopLoss()= NormalizeDouble(P, eDigits)) { double new_sl = NormalizeDouble(bid - TSTP, eDigits); if(TickSize > 0) // Adjust for tick size granularity. { new_sl = NormalizeDouble(MathRound(new_sl / TickSize) * TickSize, eDigits); } if((TSTP != 0) && (OrderStopLoss() < new_sl)) { ModifyOrder(OrderTicket(), OrderOpenPrice(), new_sl, OrderTakeProfit(), OrderSymbol()); } } } else if(OrderStopLoss()>OrderOpenPrice()) { // From StopLoss if(NormalizeDouble(bid - OrderStopLoss(), eDigits) >= NormalizeDouble(P, eDigits)) { double new_sl = NormalizeDouble(bid - TSTP, eDigits); if(TickSize > 0) // Adjust for tick size granularity. { new_sl = NormalizeDouble(MathRound(new_sl / TickSize) * TickSize, eDigits); } if((TSTP != 0) && (OrderStopLoss() < new_sl)) { ModifyOrder(OrderTicket(), OrderOpenPrice(), new_sl, OrderTakeProfit(), OrderSymbol()); } } } } else if(OrderType() == OP_SELL) { if(OrderStopLoss()>OrderOpenPrice() || OrderStopLoss()==0) { if(NormalizeDouble(OrderOpenPrice() - ask, eDigits) >= NormalizeDouble(P, eDigits)) { double new_sl = NormalizeDouble(ask + TSTP, eDigits); if(TickSize > 0) // Adjust for tick size granularity. { new_sl = NormalizeDouble(MathRound(new_sl / TickSize) * TickSize, eDigits); } if((TSTP != 0) && ((OrderStopLoss() > new_sl) || (OrderStopLoss() == 0))) { ModifyOrder(OrderTicket(), OrderOpenPrice(), new_sl, OrderTakeProfit(), OrderSymbol()); } } } else if(OrderStopLoss()= NormalizeDouble(P, eDigits)) { double new_sl = NormalizeDouble(ask + TSTP, eDigits); if(TickSize > 0) // Adjust for tick size granularity. { new_sl = NormalizeDouble(MathRound(new_sl / TickSize) * TickSize, eDigits); } if((TSTP != 0) && ((OrderStopLoss() > new_sl) || (OrderStopLoss() == 0))) { ModifyOrder(OrderTicket(), OrderOpenPrice(), new_sl, OrderTakeProfit(), OrderSymbol()); } } } } } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void ModifyOrder(int Ticket, double OpenPrice, double SLPrice, double TPPrice, string symbol) { for(int i = 1; i <= 2; i++) // Several attempts to modify the order. { bool result = OrderModify(Ticket, OpenPrice, SLPrice, TPPrice, 0); if(result) { Print("TRADE - UPDATE SUCCESS - Order ", Ticket, " new stop-loss ", SLPrice); break; } else { int Error = GetLastError(); Print("ERROR - UPDATE FAILED - error modifying order ", Ticket, " return error: ", Error, " Open=", OpenPrice, " Old SL=", OrderStopLoss(), " New SL=", SLPrice, " Bid=", MarketInfo(symbol, MODE_BID), " Ask=", MarketInfo(symbol, MODE_ASK)); } } } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //////////////////////////////////////// double NS(int m) { double ts1=0; for(int i=0; i 0) { double RiskAmount = AccountEquity * RiskPercentage / 100; // Calculate risk amount LotSizex = RiskAmount / AccountBalance; // Calculate lot size } return LotSizex; } //+------------------------------------------------------------------+ //+---------------------------------------------------------------------+ double fbo(int m) { double z=0,zz=0; for(int i=OrdersTotal(); i>=0; i--) { int a=OrderSelect(i,SELECT_BY_POS,MODE_TRADES); if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderMagicNumber()==m) { z=OrderOpenPrice(); if(z=0; i--) { int a=OrderSelect(i,SELECT_BY_POS,MODE_TRADES); if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==m) { z=OrderOpenPrice(); } if(z>zz || zz==0) zz=z; } return zz; } //+------------------------------------------------------------------+