The One Who Makes The Thunder Roar Also Hears A Butterfly Sigh - Ruzbeh
Similar Threads
I will code your pivot EAs for no charge 28 replies
I will code your scalping EAs for no charge 163 replies
Oanda MT4 - Indicators and EAs not showing 2 replies
EAs and indicators relating to moutaki... 22 replies
InterbankFX has loaded its MT4 platform with custom EAs, indicators and scripts 1 reply
- #39,422
- Sep 14, 2020 11:31am Sep 14, 2020 11:31am
- Joined Apr 2017 | Status: Trader | 1,132 Posts
PLEASE I NEED HELP!! HIGHLY APPRECIATE YOUR EFFORTS.
CAN CODER HELP ME TO MAKE THIS PENDING ORDERS AFTER GET FILLED, STOPLOSS/TAKEPROFIT IMMEDIATELY OPEN ANOTHER PENDING TO REPLACE THE PRICE THAT GOT FILLED, EA WILL ALWAYS CHECK IF PENDING IS PLACED ON SPECIFIED PRICE, IF NONE WILL PLACE ANYONE MISSING,
enum MM {Manually_Lot, Automatically_Lot};
//=========================================================================================================================================================================//
extern string OpenOrdersSets = "||========== Open Orders Sets ==========||";
extern double PriceOpen_BuyStop = 0.0;//Price Place Buy Stop (0=Not place)
extern double PriceOpen_SellStop = 0.0;//Price Place Sell Stop (0=Not place)
extern double PriceOpen_BuyLimit = 0.0;//Price Place Buy Limit (0=Not place)
extern double PriceOpen_SellLimit = 0.0;//Price Place Sell Limit (0=Not place)
extern string OrdersParameters = "||========== Orders' Parameters Sets ==========||";
extern double TakeProfit = 10;//Orders' Take Profit (0=Not Add Take Profit)
extern double StopLoss = 10;//Orders' Stop Loss (0=Not Add Stop Loss)
extern bool TrailingStopLoss = false;//Modify Stop Loss
extern double StepTrailing = 1.0;//Step Modify Stop Loss
extern bool BreakEvenRun = false;//Use Break Even
extern double BreakEvenAfter = 10.0;//Profit To Activate Break Even (Plus Stop Loss)
extern int MinutesExpire = 60;//Minutes Expiry Pending Orders (0=Without Expiry)
extern string RiskFactorSet = "||========== Risk Factor Sets ==========||";
extern MM TypeOfLotSize = Manually_Lot;//Type Of Lot Size
extern double RiskFactor = 1.0;//Risk Factro For Auto Lot
extern double ManualLotSize = 0.01;//Manual Lot Size
extern string HandleOrders = "||========== Handle Orders Sets ==========||";
extern int MagicNumber = 12345;//Orders' Handle Magic Number
//=========================================================================================================================================================================//
string ExpertName;
int MultiplierPoint;
int i;
int CntTicks;
double DigitPoint;
double LotSize;
double StopLevel;
string BackgroundName;
color ChartColor;
bool SendBS=true;
bool SendSS=true;
bool SendBL=true;
bool SendSL=true;
//=========================================================================================================================================================================//
int OnInit()
{
//---------------------------------------------------------------------
//Background
BackgroundName="Background-"+WindowExpertName();
ChartColor=(color)ChartGetInteger(0,CHART_COLOR_BACKGROUND,0);
if(ObjectFind(BackgroundName)==-1)
ChartBackground(BackgroundName,ChartColor,0,15,180,121);
//---------------------------------------------------------------------
//Broker 4 or 5 digits
DigitPoint=MarketInfo(Symbol(),MODE_POINT);
MultiplierPoint=1;
if(MarketInfo(Symbol(),MODE_DIGITS)==3||MarketInfo(Symbol(),MODE_DIGITS)==5)
{
MultiplierPoint=10;
DigitPoint*=MultiplierPoint;
}
//---------------------------------------------------------------------
//Minimum take profit and stop loss and distance for pendings
StopLevel=MathMax(MarketInfo(Symbol(),MODE_FREEZELEVEL)/MultiplierPoint,MarketInfo(Symbol(),MODE_STOPLEVEL)/MultiplierPoint);
if((TakeProfit>0)&&(TakeProfit<StopLevel))
TakeProfit=StopLevel;
if((StopLoss>0)&&(StopLoss<StopLevel))
StopLoss=StopLevel;
//---------------------------------------------------------------------
//Confirm value
if(PriceOpen_BuyStop<0)
PriceOpen_BuyStop=0.0;
if(PriceOpen_SellStop<0)
PriceOpen_SellStop=0.0;
if(PriceOpen_BuyLimit<0)
PriceOpen_BuyLimit=0.0;
if(PriceOpen_SellLimit<0)
PriceOpen_SellLimit=0.0;
//---------------------------------------------------------------------
//Reset value
CntTicks=0;
SendBS=true;
SendSS=true;
SendBL=true;
SendSL=true;
//---------------------------------------------------------------------
ExpertName=WindowExpertName();
//---------------------------------------------------------------------
OnTick();
//---------------------------------------------------------------------
return(INIT_SUCCEEDED);
//---------------------------------------------------------------------
}
//=========================================================================================================================================================================//
void OnDeinit(const int reason)
{
//---------------------------------------------------------------------
ObjectDelete(BackgroundName);
Comment("");
//---------------------------------------------------------------------
}
//=========================================================================================================================================================================//
void OnTick()
{
//---------------------------------------------------------------------
datetime Expire=0;
double FreeMargin=0;
bool WasOrderModify=false;
int OpenOrderTicket;
double SpreadPair=0;
double DistAsk=0;
double DistBid=0;
double TP=0;
double SL=0;
//---------------------------------------------------------------------
//Set expiry time
if(MinutesExpire>0)
Expire=TimeCurrent()+(MinutesExpire*60);
//---------------------------------------------------------------------
//Get spread
SpreadPair=Ask-Bid;
//---------------------------------------------------------------------
//Set levels
double OrderTP=NormalizeDouble(TakeProfit*DigitPoint,Digits);
double OrderSL=NormalizeDouble(StopLoss*DigitPoint,Digits);
double PipsAfter=NormalizeDouble(BreakEvenAfter*DigitPoint,Digits);
double TrailingStep=NormalizeDouble(StepTrailing*DigitPoint,Digits);
//------------------------------------------------------
//Set lot size
if(TypeOfLotSize==0)
LotSize=ManualLotSize;
if(TypeOfLotSize==1)
LotSize=(AccountBalance()/MarketInfo(Symbol(),MODE_LOTSIZE))*RiskFactor;
//---------------------------------------------------------------------
CommentScreen();
//---------------------------------------------------------------------
if(CntTicks<3)
CntTicks++;
if(CntTicks<3)
return;
//---------------------------------------------------------------------
//Open orders
//---Open pending stop
if((PriceOpen_BuyStop>0.0)||(PriceOpen_SellStop>0.0))
{
//---Open buy stop
if((PriceOpen_BuyStop>0.0)&&(isMgNum(MagicNumber,OP_BUYSTOP)==0)&&(SendBS==true))
{
FreeMargin=AccountFreeMargin()+AccountFreeMarginCheck(Symbol(),OP_BUY,LotSize);
//---
while(FreeMargin>=0)
{
TP=0;
SL=0;
//---
DistAsk=MathMax(NormalizeDouble(Ask+StopLevel,Digits),NormalizeDouble(PriceOpen_BuyStop,Digits));
DistBid=MathMax(NormalizeDouble(Bid+StopLevel,Digits),NormalizeDouble(PriceOpen_BuyStop-SpreadPair,Digits));
//---
if(TakeProfit>0)
TP=NormalizeDouble(DistAsk+OrderTP,Digits);
if(StopLoss>0)
SL=NormalizeDouble(DistBid-OrderSL,Digits);
//---
OpenOrderTicket=OrderSend(Symbol(),OP_BUYSTOP,NormalizeLot(LotSize),DistAsk,3,SL,TP,ExpertName,MagicNumber,Expire,clrBlue);
//---
if(OpenOrderTicket>0)
{
SendBS=false;
Print(ExpertName+" M"+IntegerToString(Period())+" "+"open buystop order");
break;
}
else
{
Print(ExpertName+": receives new data and try again open order");
Sleep(100);
RefreshRates();
}
}
}
//---Open sell stop
if((PriceOpen_SellStop>0.0)&&(isMgNum(MagicNumber,OP_SELLSTOP)==0)&&(SendSS==true))
{
FreeMargin=AccountFreeMargin()+AccountFreeMarginCheck(Symbol(),OP_SELL,LotSize);
//---
while(FreeMargin>=0)
{
TP=0;
SL=0;
//---
DistAsk=MathMin(NormalizeDouble(Ask-StopLevel,Digits),NormalizeDouble(PriceOpen_SellStop+SpreadPair,Digits));
DistBid=MathMin(NormalizeDouble(Bid-StopLevel,Digits),NormalizeDouble(PriceOpen_SellStop,Digits));
//---
if(TakeProfit>0)
TP=NormalizeDouble(DistBid-OrderTP,Digits);
if(StopLoss>0)
SL=NormalizeDouble(DistAsk+OrderSL,Digits);
//---
OpenOrderTicket=OrderSend(Symbol(),OP_SELLSTOP,NormalizeLot(LotSize),DistBid,3,SL,TP,ExpertName,MagicNumber,Expire,clrRed);
//---
if(OpenOrderTicket>0)
{
SendSS=false;
Print(ExpertName+" M"+IntegerToString(Period())+" "+"open sellstop order");
break;
}
else
{
Print(ExpertName+": receives new data and try again open order");
Sleep(100);
RefreshRates();
}
}
}
Sleep(1000);
}
//---Open pending limit
if((PriceOpen_BuyLimit>0.0)||(PriceOpen_SellLimit>0.0))
{
//---Open buy limit
if((PriceOpen_BuyLimit>0.0)&&(isMgNum(MagicNumber,OP_BUYLIMIT)==0)&&(SendBL==true))
{
FreeMargin=AccountFreeMargin()+AccountFreeMarginCheck(Symbol(),OP_BUY,LotSize);
//---
while(FreeMargin>=0)
{
TP=0;
SL=0;
//---
DistAsk=MathMin(NormalizeDouble(Ask-StopLevel,Digits),NormalizeDouble(PriceOpen_BuyLimit+SpreadPair,Digits));
DistBid=MathMin(NormalizeDouble(Bid-StopLevel,Digits),NormalizeDouble(PriceOpen_BuyLimit,Digits));
//---
if(TakeProfit>0)
TP=NormalizeDouble(DistAsk+OrderTP,Digits);
if(StopLoss>0)
SL=NormalizeDouble(DistBid-OrderSL,Digits);
//---
OpenOrderTicket=OrderSend(Symbol(),OP_BUYLIMIT,NormalizeLot(LotSize),DistBid,3,SL,TP,ExpertName,MagicNumber,Expire,clrBlue);
//---
if(OpenOrderTicket>0)
{
SendBL=false;
Print(ExpertName+" M"+IntegerToString(Period())+" "+"open buylimit order");
break;
}
else
{
Print(ExpertName+": receives new data and try again open order");
Sleep(100);
RefreshRates();
}
}
}
//---Open sell limit
if((PriceOpen_SellLimit>0.0)&&(isMgNum(MagicNumber,OP_SELLLIMIT)==0)&&(SendSL==true))
{
FreeMargin=AccountFreeMargin()+AccountFreeMarginCheck(Symbol(),OP_SELL,LotSize);
//---
while(FreeMargin>=0)
{
TP=0;
SL=0;
//---
DistAsk=MathMax(NormalizeDouble(Ask+StopLevel,Digits),NormalizeDouble(PriceOpen_SellLimit,Digits));
DistBid=MathMax(NormalizeDouble(Bid+StopLevel,Digits),NormalizeDouble(PriceOpen_SellLimit-SpreadPair,Digits));
//---
if(TakeProfit>0)
TP=NormalizeDouble(DistBid-OrderTP,Digits);
if(StopLoss>0)
SL=NormalizeDouble(DistAsk+OrderSL,Digits);
//---
OpenOrderTicket=OrderSend(Symbol(),OP_SELLLIMIT,NormalizeLot(LotSize),DistAsk,3,SL,TP,ExpertName,MagicNumber,Expire,clrRed);
//---
if(OpenOrderTicket>0)
{
SendSL=false;
Print(ExpertName+" M"+IntegerToString(Period())+" "+"open selllimit order");
break;
}
else
{
Print(ExpertName+": receives new data and try again open order");
Sleep(100);
RefreshRates();
}
}
}
Sleep(1000);
}
//---------------------------------------------------------------------
//Modify orders
if((TrailingStopLoss==true)||(BreakEvenRun==true))
{
for(i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
//---Modify sl with tsl with be
if((TrailingStopLoss==true)&&(BreakEvenRun==true)&&(StopLoss>0))
{
//--Modify buy
if((OrderType()==OP_BUY)&&(Bid-OrderStopLoss()>OrderSL+TrailingStep)&&(Bid-OrderOpenPrice()>=PipsAfter+OrderSL))
{
while(true)
{
WasOrderModify=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-OrderSL,Digits),OrderTakeProfit(),0,clrBlue);
//---
if(WasOrderModify>0)
{
Print(ExpertName+" M"+IntegerToString(Period())+" "+"modify buy 0rder");
break;
}
else
{
Print(ExpertName+": receives new data and try again modify order");
Sleep(100);
RefreshRates();
}
}
}
//--Modify sell
if((OrderType()==OP_SELL)&&(OrderStopLoss()-Ask>OrderSL+TrailingStep)&&(OrderOpenPrice()-Ask>=PipsAfter+OrderSL))
{
while(true)
{
WasOrderModify=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+OrderSL,Digits),OrderTakeProfit(),0,clrBlue);
//---
if(WasOrderModify>0)
{
Print(ExpertName+" M"+IntegerToString(Period())+" "+"modify sell 0rder");
break;
}
else
{
Print(ExpertName+": receives new data and try again modify order");
Sleep(100);
RefreshRates();
}
}
}
}
//---Modify sl with tsl without be
if((TrailingStopLoss==true)&&(BreakEvenRun==false)&&(StopLoss>0))
{
//--Modify buy
if((OrderType()==OP_BUY)&&(Bid-OrderStopLoss()>OrderSL+TrailingStep))
{
while(true)
{
WasOrderModify=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-OrderSL,Digits),OrderTakeProfit(),0,clrBlue);
//---
if(WasOrderModify>0)
{
Print(ExpertName+" M"+IntegerToString(Period())+" "+"modify buy 0rder");
break;
}
else
{
Print(ExpertName+": receives new data and try again modify order");
Sleep(100);
RefreshRates();
}
}
}
//--Modify sell
if((OrderType()==OP_SELL)&&(OrderStopLoss()-Ask>OrderSL+TrailingStep))
{
while(true)
{
WasOrderModify=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+OrderSL,Digits),OrderTakeProfit(),0,clrBlue);
//---
if(WasOrderModify>0)
{
Print(ExpertName+" M"+IntegerToString(Period())+" "+"modify sell 0rder");
break;
}
else
{
Print(ExpertName+": receives new data and try again modify order");
Sleep(100);
RefreshRates();
}
}
}
}
//---Modify sl without tsl with be
if((TrailingStopLoss==false)&&(BreakEvenRun==true)&&(StopLoss>0))
{
//--Modify buy
if((OrderType()==OP_BUY)&&(Bid-OrderOpenPrice()>=PipsAfter+OrderSL)&&(OrderStopLoss()<OrderOpenPrice()))
{
while(true)
{
WasOrderModify=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-OrderSL,Digits),OrderTakeProfit(),0,clrBlue);
//---
if(WasOrderModify>0)
{
Print(ExpertName+" M"+IntegerToString(Period())+" "+"modify buy 0rder");
break;
}
else
{
Print(ExpertName+": receives new data and try again modify order");
Sleep(100);
RefreshRates();
}
}
}
//--Modify sell
if((OrderType()==OP_SELL)&&(OrderOpenPrice()-Ask>=PipsAfter+OrderSL)&&(OrderStopLoss()>OrderOpenPrice()))
{
while(true)
{
WasOrderModify=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+OrderSL,Digits),OrderTakeProfit(),0,clrBlue);
//---
if(WasOrderModify>0)
{
Print(ExpertName+" M"+IntegerToString(Period())+" "+"modify sell 0rder");
break;
}
else
{
Print(ExpertName+": receives new data and try again modify order");
Sleep(100);
RefreshRates();
}
}
}
}
}
}
}
//---------------------------------------------------------------------
}
//=========================================================================================================================================================================//
double NormalizeLot(double LotsSize)
{
//---------------------------------------------------------------------
if(IsConnected())
{
return(MathMin(MathMax((MathRound(LotsSize/MarketInfo(Symbol(),MODE_LOTSTEP))*MarketInfo(Symbol(),MODE_LOTSTEP)),MarketInfo(Symbol(),MODE_MINLOT)),MarketInfo(Symbol(),MODE_MAXLOT)));
}
else
{
return(LotsSize);
}
//---------------------------------------------------------------------
}
//=========================================================================================================================================================================//
//Get magic number orders
int isMgNum(int Magic, int OpType)
{
for(int j=0; j<OrdersTotal(); j++)
{
if(OrderSelect(j,SELECT_BY_POS,MODE_TRADES))
{
if((OrderMagicNumber()==Magic)&&(OrderSymbol()==Symbol())&&(OrderType()==OpType))
return(1);
}
}
return(0);
}
//=========================================================================================================================================================================//
void ChartBackground(string StringName,color ImageColor,int Xposition,int Yposition,int Xsize,int Ysize)
{
//---------------------------------------------------------------------
if(ObjectFind(0,StringName)==-1)
{
ObjectCreate(0,StringName,OBJ_RECTANGLE_LABEL,0,0,0,0,0);
ObjectSetInteger(0,StringName,OBJPROP_XDISTANCE,Xposition);
ObjectSetInteger(0,StringName,OBJPROP_YDISTANCE,Yposition);
ObjectSetInteger(0,StringName,OBJPROP_XSIZE,Xsize);
ObjectSetInteger(0,StringName,OBJPROP_YSIZE,Ysize);
ObjectSetInteger(0,StringName,OBJPROP_BGCOLOR,ImageColor);
ObjectSetInteger(0,StringName,OBJPROP_BORDER_TYPE,BORDER_FLAT);
ObjectSetInteger(0,StringName,OBJPROP_BORDER_COLOR,clrBlack);
ObjectSetInteger(0,StringName,OBJPROP_BACK,false);
ObjectSetInteger(0,StringName,OBJPROP_SELECTABLE,false);
ObjectSetInteger(0,StringName,OBJPROP_SELECTED,false);
ObjectSetInteger(0,StringName,OBJPROP_HIDDEN,true);
ObjectSetInteger(0,StringName,OBJPROP_ZORDER,0);
}
//---------------------------------------------------------------------
}
//=========================================================================================================================================================================//
void CommentScreen()
{
//---------------------------------------------------------------------
string MMstring="";
string StrBS;
string StrSS;
string StrBL;
string StrSL;
string StrLot;
//---------------------------------------------------------------------
if(TypeOfLotSize==0)
StrLot="Manually";
if(TypeOfLotSize==1)
StrLot="Automatically";
//---------------------------------------------------------------------
if(PriceOpen_BuyStop==0)
StrBS="Not place Buy Stop";
else
StrBS=DoubleToStr(PriceOpen_BuyStop,Digits);
if(PriceOpen_SellStop==0)
StrSS="Not place Sell Stop";
else
StrSS=DoubleToStr(PriceOpen_SellStop,Digits);
if(PriceOpen_BuyLimit==0)
StrBL="Not place Buy Limit";
else
StrBL=DoubleToStr(PriceOpen_BuyLimit,Digits);
if(PriceOpen_SellLimit==0)
StrSL="Not place Sell Limit";
else
StrSL=DoubleToStr(PriceOpen_SellLimit,Digits);
//---------------------------------------------------------------------
//Comment in chart
Comment("=========================","\n",
WindowExpertName(),"\n",
"=========================","\n",
"Price For Buy Stop: ",StrBS,"\n",
"Price For Sell Stop: ",StrSS,"\n",
"Price For Buy Limit: ",StrBL,"\n",
"Price For Sell Limit: ",StrSL,"\n",
"=========================","\n",
"Orders' Lot Size: ",StrLot," ",DoubleToStr(LotSize,2),"\n",
"=========================");
//---------------------------------------------------------------------
}
//=========================================================================================================================================================================//
CAN CODER HELP ME TO MAKE THIS PENDING ORDERS AFTER GET FILLED, STOPLOSS/TAKEPROFIT IMMEDIATELY OPEN ANOTHER PENDING TO REPLACE THE PRICE THAT GOT FILLED, EA WILL ALWAYS CHECK IF PENDING IS PLACED ON SPECIFIED PRICE, IF NONE WILL PLACE ANYONE MISSING,
enum MM {Manually_Lot, Automatically_Lot};
//=========================================================================================================================================================================//
extern string OpenOrdersSets = "||========== Open Orders Sets ==========||";
extern double PriceOpen_BuyStop = 0.0;//Price Place Buy Stop (0=Not place)
extern double PriceOpen_SellStop = 0.0;//Price Place Sell Stop (0=Not place)
extern double PriceOpen_BuyLimit = 0.0;//Price Place Buy Limit (0=Not place)
extern double PriceOpen_SellLimit = 0.0;//Price Place Sell Limit (0=Not place)
extern string OrdersParameters = "||========== Orders' Parameters Sets ==========||";
extern double TakeProfit = 10;//Orders' Take Profit (0=Not Add Take Profit)
extern double StopLoss = 10;//Orders' Stop Loss (0=Not Add Stop Loss)
extern bool TrailingStopLoss = false;//Modify Stop Loss
extern double StepTrailing = 1.0;//Step Modify Stop Loss
extern bool BreakEvenRun = false;//Use Break Even
extern double BreakEvenAfter = 10.0;//Profit To Activate Break Even (Plus Stop Loss)
extern int MinutesExpire = 60;//Minutes Expiry Pending Orders (0=Without Expiry)
extern string RiskFactorSet = "||========== Risk Factor Sets ==========||";
extern MM TypeOfLotSize = Manually_Lot;//Type Of Lot Size
extern double RiskFactor = 1.0;//Risk Factro For Auto Lot
extern double ManualLotSize = 0.01;//Manual Lot Size
extern string HandleOrders = "||========== Handle Orders Sets ==========||";
extern int MagicNumber = 12345;//Orders' Handle Magic Number
//=========================================================================================================================================================================//
string ExpertName;
int MultiplierPoint;
int i;
int CntTicks;
double DigitPoint;
double LotSize;
double StopLevel;
string BackgroundName;
color ChartColor;
bool SendBS=true;
bool SendSS=true;
bool SendBL=true;
bool SendSL=true;
//=========================================================================================================================================================================//
int OnInit()
{
//---------------------------------------------------------------------
//Background
BackgroundName="Background-"+WindowExpertName();
ChartColor=(color)ChartGetInteger(0,CHART_COLOR_BACKGROUND,0);
if(ObjectFind(BackgroundName)==-1)
ChartBackground(BackgroundName,ChartColor,0,15,180,121);
//---------------------------------------------------------------------
//Broker 4 or 5 digits
DigitPoint=MarketInfo(Symbol(),MODE_POINT);
MultiplierPoint=1;
if(MarketInfo(Symbol(),MODE_DIGITS)==3||MarketInfo(Symbol(),MODE_DIGITS)==5)
{
MultiplierPoint=10;
DigitPoint*=MultiplierPoint;
}
//---------------------------------------------------------------------
//Minimum take profit and stop loss and distance for pendings
StopLevel=MathMax(MarketInfo(Symbol(),MODE_FREEZELEVEL)/MultiplierPoint,MarketInfo(Symbol(),MODE_STOPLEVEL)/MultiplierPoint);
if((TakeProfit>0)&&(TakeProfit<StopLevel))
TakeProfit=StopLevel;
if((StopLoss>0)&&(StopLoss<StopLevel))
StopLoss=StopLevel;
//---------------------------------------------------------------------
//Confirm value
if(PriceOpen_BuyStop<0)
PriceOpen_BuyStop=0.0;
if(PriceOpen_SellStop<0)
PriceOpen_SellStop=0.0;
if(PriceOpen_BuyLimit<0)
PriceOpen_BuyLimit=0.0;
if(PriceOpen_SellLimit<0)
PriceOpen_SellLimit=0.0;
//---------------------------------------------------------------------
//Reset value
CntTicks=0;
SendBS=true;
SendSS=true;
SendBL=true;
SendSL=true;
//---------------------------------------------------------------------
ExpertName=WindowExpertName();
//---------------------------------------------------------------------
OnTick();
//---------------------------------------------------------------------
return(INIT_SUCCEEDED);
//---------------------------------------------------------------------
}
//=========================================================================================================================================================================//
void OnDeinit(const int reason)
{
//---------------------------------------------------------------------
ObjectDelete(BackgroundName);
Comment("");
//---------------------------------------------------------------------
}
//=========================================================================================================================================================================//
void OnTick()
{
//---------------------------------------------------------------------
datetime Expire=0;
double FreeMargin=0;
bool WasOrderModify=false;
int OpenOrderTicket;
double SpreadPair=0;
double DistAsk=0;
double DistBid=0;
double TP=0;
double SL=0;
//---------------------------------------------------------------------
//Set expiry time
if(MinutesExpire>0)
Expire=TimeCurrent()+(MinutesExpire*60);
//---------------------------------------------------------------------
//Get spread
SpreadPair=Ask-Bid;
//---------------------------------------------------------------------
//Set levels
double OrderTP=NormalizeDouble(TakeProfit*DigitPoint,Digits);
double OrderSL=NormalizeDouble(StopLoss*DigitPoint,Digits);
double PipsAfter=NormalizeDouble(BreakEvenAfter*DigitPoint,Digits);
double TrailingStep=NormalizeDouble(StepTrailing*DigitPoint,Digits);
//------------------------------------------------------
//Set lot size
if(TypeOfLotSize==0)
LotSize=ManualLotSize;
if(TypeOfLotSize==1)
LotSize=(AccountBalance()/MarketInfo(Symbol(),MODE_LOTSIZE))*RiskFactor;
//---------------------------------------------------------------------
CommentScreen();
//---------------------------------------------------------------------
if(CntTicks<3)
CntTicks++;
if(CntTicks<3)
return;
//---------------------------------------------------------------------
//Open orders
//---Open pending stop
if((PriceOpen_BuyStop>0.0)||(PriceOpen_SellStop>0.0))
{
//---Open buy stop
if((PriceOpen_BuyStop>0.0)&&(isMgNum(MagicNumber,OP_BUYSTOP)==0)&&(SendBS==true))
{
FreeMargin=AccountFreeMargin()+AccountFreeMarginCheck(Symbol(),OP_BUY,LotSize);
//---
while(FreeMargin>=0)
{
TP=0;
SL=0;
//---
DistAsk=MathMax(NormalizeDouble(Ask+StopLevel,Digits),NormalizeDouble(PriceOpen_BuyStop,Digits));
DistBid=MathMax(NormalizeDouble(Bid+StopLevel,Digits),NormalizeDouble(PriceOpen_BuyStop-SpreadPair,Digits));
//---
if(TakeProfit>0)
TP=NormalizeDouble(DistAsk+OrderTP,Digits);
if(StopLoss>0)
SL=NormalizeDouble(DistBid-OrderSL,Digits);
//---
OpenOrderTicket=OrderSend(Symbol(),OP_BUYSTOP,NormalizeLot(LotSize),DistAsk,3,SL,TP,ExpertName,MagicNumber,Expire,clrBlue);
//---
if(OpenOrderTicket>0)
{
SendBS=false;
Print(ExpertName+" M"+IntegerToString(Period())+" "+"open buystop order");
break;
}
else
{
Print(ExpertName+": receives new data and try again open order");
Sleep(100);
RefreshRates();
}
}
}
//---Open sell stop
if((PriceOpen_SellStop>0.0)&&(isMgNum(MagicNumber,OP_SELLSTOP)==0)&&(SendSS==true))
{
FreeMargin=AccountFreeMargin()+AccountFreeMarginCheck(Symbol(),OP_SELL,LotSize);
//---
while(FreeMargin>=0)
{
TP=0;
SL=0;
//---
DistAsk=MathMin(NormalizeDouble(Ask-StopLevel,Digits),NormalizeDouble(PriceOpen_SellStop+SpreadPair,Digits));
DistBid=MathMin(NormalizeDouble(Bid-StopLevel,Digits),NormalizeDouble(PriceOpen_SellStop,Digits));
//---
if(TakeProfit>0)
TP=NormalizeDouble(DistBid-OrderTP,Digits);
if(StopLoss>0)
SL=NormalizeDouble(DistAsk+OrderSL,Digits);
//---
OpenOrderTicket=OrderSend(Symbol(),OP_SELLSTOP,NormalizeLot(LotSize),DistBid,3,SL,TP,ExpertName,MagicNumber,Expire,clrRed);
//---
if(OpenOrderTicket>0)
{
SendSS=false;
Print(ExpertName+" M"+IntegerToString(Period())+" "+"open sellstop order");
break;
}
else
{
Print(ExpertName+": receives new data and try again open order");
Sleep(100);
RefreshRates();
}
}
}
Sleep(1000);
}
//---Open pending limit
if((PriceOpen_BuyLimit>0.0)||(PriceOpen_SellLimit>0.0))
{
//---Open buy limit
if((PriceOpen_BuyLimit>0.0)&&(isMgNum(MagicNumber,OP_BUYLIMIT)==0)&&(SendBL==true))
{
FreeMargin=AccountFreeMargin()+AccountFreeMarginCheck(Symbol(),OP_BUY,LotSize);
//---
while(FreeMargin>=0)
{
TP=0;
SL=0;
//---
DistAsk=MathMin(NormalizeDouble(Ask-StopLevel,Digits),NormalizeDouble(PriceOpen_BuyLimit+SpreadPair,Digits));
DistBid=MathMin(NormalizeDouble(Bid-StopLevel,Digits),NormalizeDouble(PriceOpen_BuyLimit,Digits));
//---
if(TakeProfit>0)
TP=NormalizeDouble(DistAsk+OrderTP,Digits);
if(StopLoss>0)
SL=NormalizeDouble(DistBid-OrderSL,Digits);
//---
OpenOrderTicket=OrderSend(Symbol(),OP_BUYLIMIT,NormalizeLot(LotSize),DistBid,3,SL,TP,ExpertName,MagicNumber,Expire,clrBlue);
//---
if(OpenOrderTicket>0)
{
SendBL=false;
Print(ExpertName+" M"+IntegerToString(Period())+" "+"open buylimit order");
break;
}
else
{
Print(ExpertName+": receives new data and try again open order");
Sleep(100);
RefreshRates();
}
}
}
//---Open sell limit
if((PriceOpen_SellLimit>0.0)&&(isMgNum(MagicNumber,OP_SELLLIMIT)==0)&&(SendSL==true))
{
FreeMargin=AccountFreeMargin()+AccountFreeMarginCheck(Symbol(),OP_SELL,LotSize);
//---
while(FreeMargin>=0)
{
TP=0;
SL=0;
//---
DistAsk=MathMax(NormalizeDouble(Ask+StopLevel,Digits),NormalizeDouble(PriceOpen_SellLimit,Digits));
DistBid=MathMax(NormalizeDouble(Bid+StopLevel,Digits),NormalizeDouble(PriceOpen_SellLimit-SpreadPair,Digits));
//---
if(TakeProfit>0)
TP=NormalizeDouble(DistBid-OrderTP,Digits);
if(StopLoss>0)
SL=NormalizeDouble(DistAsk+OrderSL,Digits);
//---
OpenOrderTicket=OrderSend(Symbol(),OP_SELLLIMIT,NormalizeLot(LotSize),DistAsk,3,SL,TP,ExpertName,MagicNumber,Expire,clrRed);
//---
if(OpenOrderTicket>0)
{
SendSL=false;
Print(ExpertName+" M"+IntegerToString(Period())+" "+"open selllimit order");
break;
}
else
{
Print(ExpertName+": receives new data and try again open order");
Sleep(100);
RefreshRates();
}
}
}
Sleep(1000);
}
//---------------------------------------------------------------------
//Modify orders
if((TrailingStopLoss==true)||(BreakEvenRun==true))
{
for(i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
//---Modify sl with tsl with be
if((TrailingStopLoss==true)&&(BreakEvenRun==true)&&(StopLoss>0))
{
//--Modify buy
if((OrderType()==OP_BUY)&&(Bid-OrderStopLoss()>OrderSL+TrailingStep)&&(Bid-OrderOpenPrice()>=PipsAfter+OrderSL))
{
while(true)
{
WasOrderModify=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-OrderSL,Digits),OrderTakeProfit(),0,clrBlue);
//---
if(WasOrderModify>0)
{
Print(ExpertName+" M"+IntegerToString(Period())+" "+"modify buy 0rder");
break;
}
else
{
Print(ExpertName+": receives new data and try again modify order");
Sleep(100);
RefreshRates();
}
}
}
//--Modify sell
if((OrderType()==OP_SELL)&&(OrderStopLoss()-Ask>OrderSL+TrailingStep)&&(OrderOpenPrice()-Ask>=PipsAfter+OrderSL))
{
while(true)
{
WasOrderModify=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+OrderSL,Digits),OrderTakeProfit(),0,clrBlue);
//---
if(WasOrderModify>0)
{
Print(ExpertName+" M"+IntegerToString(Period())+" "+"modify sell 0rder");
break;
}
else
{
Print(ExpertName+": receives new data and try again modify order");
Sleep(100);
RefreshRates();
}
}
}
}
//---Modify sl with tsl without be
if((TrailingStopLoss==true)&&(BreakEvenRun==false)&&(StopLoss>0))
{
//--Modify buy
if((OrderType()==OP_BUY)&&(Bid-OrderStopLoss()>OrderSL+TrailingStep))
{
while(true)
{
WasOrderModify=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-OrderSL,Digits),OrderTakeProfit(),0,clrBlue);
//---
if(WasOrderModify>0)
{
Print(ExpertName+" M"+IntegerToString(Period())+" "+"modify buy 0rder");
break;
}
else
{
Print(ExpertName+": receives new data and try again modify order");
Sleep(100);
RefreshRates();
}
}
}
//--Modify sell
if((OrderType()==OP_SELL)&&(OrderStopLoss()-Ask>OrderSL+TrailingStep))
{
while(true)
{
WasOrderModify=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+OrderSL,Digits),OrderTakeProfit(),0,clrBlue);
//---
if(WasOrderModify>0)
{
Print(ExpertName+" M"+IntegerToString(Period())+" "+"modify sell 0rder");
break;
}
else
{
Print(ExpertName+": receives new data and try again modify order");
Sleep(100);
RefreshRates();
}
}
}
}
//---Modify sl without tsl with be
if((TrailingStopLoss==false)&&(BreakEvenRun==true)&&(StopLoss>0))
{
//--Modify buy
if((OrderType()==OP_BUY)&&(Bid-OrderOpenPrice()>=PipsAfter+OrderSL)&&(OrderStopLoss()<OrderOpenPrice()))
{
while(true)
{
WasOrderModify=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-OrderSL,Digits),OrderTakeProfit(),0,clrBlue);
//---
if(WasOrderModify>0)
{
Print(ExpertName+" M"+IntegerToString(Period())+" "+"modify buy 0rder");
break;
}
else
{
Print(ExpertName+": receives new data and try again modify order");
Sleep(100);
RefreshRates();
}
}
}
//--Modify sell
if((OrderType()==OP_SELL)&&(OrderOpenPrice()-Ask>=PipsAfter+OrderSL)&&(OrderStopLoss()>OrderOpenPrice()))
{
while(true)
{
WasOrderModify=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+OrderSL,Digits),OrderTakeProfit(),0,clrBlue);
//---
if(WasOrderModify>0)
{
Print(ExpertName+" M"+IntegerToString(Period())+" "+"modify sell 0rder");
break;
}
else
{
Print(ExpertName+": receives new data and try again modify order");
Sleep(100);
RefreshRates();
}
}
}
}
}
}
}
//---------------------------------------------------------------------
}
//=========================================================================================================================================================================//
double NormalizeLot(double LotsSize)
{
//---------------------------------------------------------------------
if(IsConnected())
{
return(MathMin(MathMax((MathRound(LotsSize/MarketInfo(Symbol(),MODE_LOTSTEP))*MarketInfo(Symbol(),MODE_LOTSTEP)),MarketInfo(Symbol(),MODE_MINLOT)),MarketInfo(Symbol(),MODE_MAXLOT)));
}
else
{
return(LotsSize);
}
//---------------------------------------------------------------------
}
//=========================================================================================================================================================================//
//Get magic number orders
int isMgNum(int Magic, int OpType)
{
for(int j=0; j<OrdersTotal(); j++)
{
if(OrderSelect(j,SELECT_BY_POS,MODE_TRADES))
{
if((OrderMagicNumber()==Magic)&&(OrderSymbol()==Symbol())&&(OrderType()==OpType))
return(1);
}
}
return(0);
}
//=========================================================================================================================================================================//
void ChartBackground(string StringName,color ImageColor,int Xposition,int Yposition,int Xsize,int Ysize)
{
//---------------------------------------------------------------------
if(ObjectFind(0,StringName)==-1)
{
ObjectCreate(0,StringName,OBJ_RECTANGLE_LABEL,0,0,0,0,0);
ObjectSetInteger(0,StringName,OBJPROP_XDISTANCE,Xposition);
ObjectSetInteger(0,StringName,OBJPROP_YDISTANCE,Yposition);
ObjectSetInteger(0,StringName,OBJPROP_XSIZE,Xsize);
ObjectSetInteger(0,StringName,OBJPROP_YSIZE,Ysize);
ObjectSetInteger(0,StringName,OBJPROP_BGCOLOR,ImageColor);
ObjectSetInteger(0,StringName,OBJPROP_BORDER_TYPE,BORDER_FLAT);
ObjectSetInteger(0,StringName,OBJPROP_BORDER_COLOR,clrBlack);
ObjectSetInteger(0,StringName,OBJPROP_BACK,false);
ObjectSetInteger(0,StringName,OBJPROP_SELECTABLE,false);
ObjectSetInteger(0,StringName,OBJPROP_SELECTED,false);
ObjectSetInteger(0,StringName,OBJPROP_HIDDEN,true);
ObjectSetInteger(0,StringName,OBJPROP_ZORDER,0);
}
//---------------------------------------------------------------------
}
//=========================================================================================================================================================================//
void CommentScreen()
{
//---------------------------------------------------------------------
string MMstring="";
string StrBS;
string StrSS;
string StrBL;
string StrSL;
string StrLot;
//---------------------------------------------------------------------
if(TypeOfLotSize==0)
StrLot="Manually";
if(TypeOfLotSize==1)
StrLot="Automatically";
//---------------------------------------------------------------------
if(PriceOpen_BuyStop==0)
StrBS="Not place Buy Stop";
else
StrBS=DoubleToStr(PriceOpen_BuyStop,Digits);
if(PriceOpen_SellStop==0)
StrSS="Not place Sell Stop";
else
StrSS=DoubleToStr(PriceOpen_SellStop,Digits);
if(PriceOpen_BuyLimit==0)
StrBL="Not place Buy Limit";
else
StrBL=DoubleToStr(PriceOpen_BuyLimit,Digits);
if(PriceOpen_SellLimit==0)
StrSL="Not place Sell Limit";
else
StrSL=DoubleToStr(PriceOpen_SellLimit,Digits);
//---------------------------------------------------------------------
//Comment in chart
Comment("=========================","\n",
WindowExpertName(),"\n",
"=========================","\n",
"Price For Buy Stop: ",StrBS,"\n",
"Price For Sell Stop: ",StrSS,"\n",
"Price For Buy Limit: ",StrBL,"\n",
"Price For Sell Limit: ",StrSL,"\n",
"=========================","\n",
"Orders' Lot Size: ",StrLot," ",DoubleToStr(LotSize,2),"\n",
"=========================");
//---------------------------------------------------------------------
}
//=========================================================================================================================================================================//
- #39,424
- Edited 12:35pm Sep 14, 2020 12:22pm | Edited 12:35pm
- Joined Mar 2013 | Status: Trader | 2,466 Posts
DislikedPLEASE I NEED HELP!! HIGHLY APPRECIATE YOUR EFFORTS. CAN CODER HELP ME TO MAKE THIS PENDING ORDERS AFTER GET FILLED, STOPLOSS/TAKEPROFIT IMMEDIATELY OPEN ANOTHER PENDING TO REPLACE THE PRICE THAT GOT FILLED, EA WILL ALWAYS CHECK IF PENDING IS PLACED ON SPECIFIED PRICE, IF NONE WILL PLACE ANYONE MISSING, enum MM {Manually_Lot, Automatically_Lot}; //=========================================================================================================================================================================// extern string OpenOrdersSets...Ignored
and small letters (lowercase) as opposed to capital letters that in no way take special consideration and attention but a kind of rude and .....
For example
Inserted Code
enum MM {Manually_Lot, Automatically_Lot};
//=========================================================================================================================================================================//
extern string OpenOrdersSets = "||========== Open Orders Sets ==========||";
extern double PriceOpen_BuyStop = 0.0;//Price Place Buy Stop (0=Not place)
extern double PriceOpen_SellStop = 0.0;//Price Place Sell Stop (0=Not place)
extern double PriceOpen_BuyLimit = 0.0;//Price Place Buy Limit (0=Not place)
extern double PriceOpen_SellLimit = 0.0;//Price Place Sell Limit (0=Not place)
extern string OrdersParameters = "||========== Orders' Parameters Sets ==========||";
extern double TakeProfit = 10;//Orders' Take Profit (0=Not Add Take Profit)
extern double StopLoss = 10;//Orders' Stop Loss (0=Not Add Stop Loss)
extern bool TrailingStopLoss = false;//Modify Stop Loss
extern double StepTrailing = 1.0;//Step Modify Stop Loss
extern bool BreakEvenRun = false;//Use Break Even
extern double BreakEvenAfter = 10.0;//Profit To Activate Break Even (Plus Stop Loss)
extern int MinutesExpire = 60;//Minutes Expiry Pending Orders (0=Without Expiry)
extern string RiskFactorSet = "||========== Risk Factor Sets ==========||";
extern MM TypeOfLotSize = Manually_Lot;//Type Of Lot Size
extern double RiskFactor = 1.0;//Risk Factro For Auto Lot
extern double ManualLotSize = 0.01;//Manual Lot Size
extern string HandleOrders = "||========== Handle Orders Sets ==========||";
extern int MagicNumber = 12345;//Orders' Handle Magic Number
//=========================================================================================================================================================================//
string ExpertName;
int MultiplierPoint;
int i;
int CntTicks;
double DigitPoint;
double LotSize;
double StopLevel;
string BackgroundName;
color ChartColor;
bool SendBS=true;
bool SendSS=true;
bool SendBL=true;
bool SendSL=true;
//=========================================================================================================================================================================//
int OnInit()
{
//---------------------------------------------------------------------
//Background
BackgroundName="Background-"+WindowExpertName();
ChartColor=(color)ChartGetInteger(0,CHART_COLOR_BACKGROUND,0);
if(ObjectFind(BackgroundName)==-1)
ChartBackground(BackgroundName,ChartColor,0,15,180,121);
//---------------------------------------------------------------------
//Broker 4 or 5 digits
DigitPoint=MarketInfo(Symbol(),MODE_POINT);
MultiplierPoint=1;
if(MarketInfo(Symbol(),MODE_DIGITS)==3||MarketInfo(Symbol(),MODE_DIGITS)==5)
{
MultiplierPoint=10;
DigitPoint*=MultiplierPoint;
}
//---------------------------------------------------------------------
//Minimum take profit and stop loss and distance for pendings
StopLevel=MathMax(MarketInfo(Symbol(),MODE_FREEZELEVEL)/MultiplierPoint,MarketInfo(Symbol(),MODE_STOPLEVEL)/MultiplierPoint);
if((TakeProfit>0)&&(TakeProfit<StopLevel))
TakeProfit=StopLevel;
if((StopLoss>0)&&(StopLoss<StopLevel))
StopLoss=StopLevel;
//---------------------------------------------------------------------
//Confirm value
if(PriceOpen_BuyStop<0)
PriceOpen_BuyStop=0.0;
if(PriceOpen_SellStop<0)
PriceOpen_SellStop=0.0;
if(PriceOpen_BuyLimit<0)
PriceOpen_BuyLimit=0.0;
if(PriceOpen_SellLimit<0)
PriceOpen_SellLimit=0.0;
//---------------------------------------------------------------------
//Reset value
CntTicks=0;
SendBS=true;
SendSS=true;
SendBL=true;
SendSL=true;
//---------------------------------------------------------------------
ExpertName=WindowExpertName();
//---------------------------------------------------------------------
OnTick();
//---------------------------------------------------------------------
return(INIT_SUCCEEDED);
//---------------------------------------------------------------------
}
//=========================================================================================================================================================================//
void OnDeinit(const int reason)
{
//---------------------------------------------------------------------
ObjectDelete(BackgroundName);
Comment("");
//---------------------------------------------------------------------
}
//=========================================================================================================================================================================//
void OnTick()
{
//---------------------------------------------------------------------
datetime Expire=0;
double FreeMargin=0;
bool WasOrderModify=false;
int OpenOrderTicket;
double SpreadPair=0;
double DistAsk=0;
double DistBid=0;
double TP=0;
double SL=0;
//---------------------------------------------------------------------
//Set expiry time
if(MinutesExpire>0)
Expire=TimeCurrent()+(MinutesExpire*60);
//---------------------------------------------------------------------
//Get spread
SpreadPair=Ask-Bid;
//---------------------------------------------------------------------
//Set levels
double OrderTP=NormalizeDouble(TakeProfit*DigitPoint,Digits);
double OrderSL=NormalizeDouble(StopLoss*DigitPoint,Digits);
double PipsAfter=NormalizeDouble(BreakEvenAfter*DigitPoint,Digits);
double TrailingStep=NormalizeDouble(StepTrailing*DigitPoint,Digits);
//------------------------------------------------------
//Set lot size
if(TypeOfLotSize==0)
LotSize=ManualLotSize;
if(TypeOfLotSize==1)
LotSize=(AccountBalance()/MarketInfo(Symbol(),MODE_LOTSIZE))*RiskFactor;
//---------------------------------------------------------------------
CommentScreen();
//---------------------------------------------------------------------
if(CntTicks<3)
CntTicks++;
if(CntTicks<3)
return;
//---------------------------------------------------------------------
//Open orders
//---Open pending stop
if((PriceOpen_BuyStop>0.0)||(PriceOpen_SellStop>0.0))
{
//---Open buy stop
if((PriceOpen_BuyStop>0.0)&&(isMgNum(MagicNumber,OP_BUYSTOP)==0)&&(SendBS==true))
{
FreeMargin=AccountFreeMargin()+AccountFreeMarginCheck(Symbol(),OP_BUY,LotSize);
//---
while(FreeMargin>=0)
{
TP=0;
SL=0;
//---
DistAsk=MathMax(NormalizeDouble(Ask+StopLevel,Digits),NormalizeDouble(PriceOpen_BuyStop,Digits));
DistBid=MathMax(NormalizeDouble(Bid+StopLevel,Digits),NormalizeDouble(PriceOpen_BuyStop-SpreadPair,Digits));
//---
if(TakeProfit>0)
TP=NormalizeDouble(DistAsk+OrderTP,Digits);
if(StopLoss>0)
SL=NormalizeDouble(DistBid-OrderSL,Digits);
//---
OpenOrderTicket=OrderSend(Symbol(),OP_BUYSTOP,NormalizeLot(LotSize),DistAsk,3,SL,TP,ExpertName,MagicNumber,Expire,clrBlue);
//---
if(OpenOrderTicket>0)
{
SendBS=false;
Print(ExpertName+" M"+IntegerToString(Period())+" "+"open buystop order");
break;
}
else
{
Print(ExpertName+": receives new data and try again open order");
Sleep(100);
RefreshRates();
}
}
}
//---Open sell stop
if((PriceOpen_SellStop>0.0)&&(isMgNum(MagicNumber,OP_SELLSTOP)==0)&&(SendSS==true))
{
FreeMargin=AccountFreeMargin()+AccountFreeMarginCheck(Symbol(),OP_SELL,LotSize);
//---
while(FreeMargin>=0)
{
TP=0;
SL=0;
//---
DistAsk=MathMin(NormalizeDouble(Ask-StopLevel,Digits),NormalizeDouble(PriceOpen_SellStop+SpreadPair,Digits));
DistBid=MathMin(NormalizeDouble(Bid-StopLevel,Digits),NormalizeDouble(PriceOpen_SellStop,Digits));
//---
if(TakeProfit>0)
TP=NormalizeDouble(DistBid-OrderTP,Digits);
if(StopLoss>0)
SL=NormalizeDouble(DistAsk+OrderSL,Digits);
//---
OpenOrderTicket=OrderSend(Symbol(),OP_SELLSTOP,NormalizeLot(LotSize),DistBid,3,SL,TP,ExpertName,MagicNumber,Expire,clrRed);
//---
if(OpenOrderTicket>0)
{
SendSS=false;
Print(ExpertName+" M"+IntegerToString(Period())+" "+"open sellstop order");
break;
}
else
{
Print(ExpertName+": receives new data and try again open order");
Sleep(100);
RefreshRates();
}
}
}
Sleep(1000);
}
//---Open pending limit
if((PriceOpen_BuyLimit>0.0)||(PriceOpen_SellLimit>0.0))
{
//---Open buy limit
if((PriceOpen_BuyLimit>0.0)&&(isMgNum(MagicNumber,OP_BUYLIMIT)==0)&&(SendBL==true))
{
FreeMargin=AccountFreeMargin()+AccountFreeMarginCheck(Symbol(),OP_BUY,LotSize);
//---
while(FreeMargin>=0)
{
TP=0;
SL=0;
//---
DistAsk=MathMin(NormalizeDouble(Ask-StopLevel,Digits),NormalizeDouble(PriceOpen_BuyLimit+SpreadPair,Digits));
DistBid=MathMin(NormalizeDouble(Bid-StopLevel,Digits),NormalizeDouble(PriceOpen_BuyLimit,Digits));
//---
if(TakeProfit>0)
TP=NormalizeDouble(DistAsk+OrderTP,Digits);
if(StopLoss>0)
SL=NormalizeDouble(DistBid-OrderSL,Digits);
//---
OpenOrderTicket=OrderSend(Symbol(),OP_BUYLIMIT,NormalizeLot(LotSize),DistBid,3,SL,TP,ExpertName,MagicNumber,Expire,clrBlue);
//---
if(OpenOrderTicket>0)
{
SendBL=false;
Print(ExpertName+" M"+IntegerToString(Period())+" "+"open buylimit order");
break;
}
else
{
Print(ExpertName+": receives new data and try again open order");
Sleep(100);
RefreshRates();
}
}
}
//---Open sell limit
if((PriceOpen_SellLimit>0.0)&&(isMgNum(MagicNumber,OP_SELLLIMIT)==0)&&(SendSL==true))
{
FreeMargin=AccountFreeMargin()+AccountFreeMarginCheck(Symbol(),OP_SELL,LotSize);
//---
while(FreeMargin>=0)
{
TP=0;
SL=0;
//---
DistAsk=MathMax(NormalizeDouble(Ask+StopLevel,Digits),NormalizeDouble(PriceOpen_SellLimit,Digits));
DistBid=MathMax(NormalizeDouble(Bid+StopLevel,Digits),NormalizeDouble(PriceOpen_SellLimit-SpreadPair,Digits));
//---
if(TakeProfit>0)
TP=NormalizeDouble(DistBid-OrderTP,Digits);
if(StopLoss>0)
SL=NormalizeDouble(DistAsk+OrderSL,Digits);
//---
OpenOrderTicket=OrderSend(Symbol(),OP_SELLLIMIT,NormalizeLot(LotSize),DistAsk,3,SL,TP,ExpertName,MagicNumber,Expire,clrRed);
//---
if(OpenOrderTicket>0)
{
SendSL=false;
Print(ExpertName+" M"+IntegerToString(Period())+" "+"open selllimit order");
break;
}
else
{
Print(ExpertName+": receives new data and try again open order");
Sleep(100);
RefreshRates();
}
}
}
Sleep(1000);
}
//---------------------------------------------------------------------
//Modify orders
if((TrailingStopLoss==true)||(BreakEvenRun==true))
{
for(i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
//---Modify sl with tsl with be
if((TrailingStopLoss==true)&&(BreakEvenRun==true)&&(StopLoss>0))
{
//--Modify buy
if((OrderType()==OP_BUY)&&(Bid-OrderStopLoss()>OrderSL+TrailingStep)&&(Bid-OrderOpenPrice()>=PipsAfter+OrderSL))
{
while(true)
{
WasOrderModify=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-OrderSL,Digits),OrderTakeProfit(),0,clrBlue);
//---
if(WasOrderModify>0)
{
Print(ExpertName+" M"+IntegerToString(Period())+" "+"modify buy 0rder");
break;
}
else
{
Print(ExpertName+": receives new data and try again modify order");
Sleep(100);
RefreshRates();
}
}
}
//--Modify sell
if((OrderType()==OP_SELL)&&(OrderStopLoss()-Ask>OrderSL+TrailingStep)&&(OrderOpenPrice()-Ask>=PipsAfter+OrderSL))
{
while(true)
{
WasOrderModify=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+OrderSL,Digits),OrderTakeProfit(),0,clrBlue);
//---
if(WasOrderModify>0)
{
Print(ExpertName+" M"+IntegerToString(Period())+" "+"modify sell 0rder");
break;
}
else
{
Print(ExpertName+": receives new data and try again modify order");
Sleep(100);
RefreshRates();
}
}
}
}
//---Modify sl with tsl without be
if((TrailingStopLoss==true)&&(BreakEvenRun==false)&&(StopLoss>0))
{
//--Modify buy
if((OrderType()==OP_BUY)&&(Bid-OrderStopLoss()>OrderSL+TrailingStep))
{
while(true)
{
WasOrderModify=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-OrderSL,Digits),OrderTakeProfit(),0,clrBlue);
//---
if(WasOrderModify>0)
{
Print(ExpertName+" M"+IntegerToString(Period())+" "+"modify buy 0rder");
break;
}
else
{
Print(ExpertName+": receives new data and try again modify order");
Sleep(100);
RefreshRates();
}
}
}
//--Modify sell
if((OrderType()==OP_SELL)&&(OrderStopLoss()-Ask>OrderSL+TrailingStep))
{
while(true)
{
WasOrderModify=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+OrderSL,Digits),OrderTakeProfit(),0,clrBlue);
//---
if(WasOrderModify>0)
{
Print(ExpertName+" M"+IntegerToString(Period())+" "+"modify sell 0rder");
break;
}
else
{
Print(ExpertName+": receives new data and try again modify order");
Sleep(100);
RefreshRates();
}
}
}
}
//---Modify sl without tsl with be
if((TrailingStopLoss==false)&&(BreakEvenRun==true)&&(StopLoss>0))
{
//--Modify buy
if((OrderType()==OP_BUY)&&(Bid-OrderOpenPrice()>=PipsAfter+OrderSL)&&(OrderStopLoss()<OrderOpenPrice()))
{
while(true)
{
WasOrderModify=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-OrderSL,Digits),OrderTakeProfit(),0,clrBlue);
//---
if(WasOrderModify>0)
{
Print(ExpertName+" M"+IntegerToString(Period())+" "+"modify buy 0rder");
break;
}
else
{
Print(ExpertName+": receives new data and try again modify order");
Sleep(100);
RefreshRates();
}
}
}
//--Modify sell
if((OrderType()==OP_SELL)&&(OrderOpenPrice()-Ask>=PipsAfter+OrderSL)&&(OrderStopLoss()>OrderOpenPrice()))
{
while(true)
{
WasOrderModify=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+OrderSL,Digits),OrderTakeProfit(),0,clrBlue);
//---
if(WasOrderModify>0)
{
Print(ExpertName+" M"+IntegerToString(Period())+" "+"modify sell 0rder");
break;
}
else
{
Print(ExpertName+": receives new data and try again modify order");
Sleep(100);
RefreshRates();
}
}
}
}
}
}
}
//---------------------------------------------------------------------
}
//=========================================================================================================================================================================//
double NormalizeLot(double LotsSize)
{
//---------------------------------------------------------------------
if(IsConnected())
{
return(MathMin(MathMax((MathRound(LotsSize/MarketInfo(Symbol(),MODE_LOTSTEP))*MarketInfo(Symbol(),MODE_LOTSTEP)),MarketInfo(Symbol(),MODE_MINLOT)),MarketInfo(Symbol(),MODE_MAXLOT)));
}
else
{
return(LotsSize);
}
//---------------------------------------------------------------------
}
//=========================================================================================================================================================================//
//Get magic number orders
int isMgNum(int Magic, int OpType)
{
for(int j=0; j<OrdersTotal(); j++)
{
if(OrderSelect(j,SELECT_BY_POS,MODE_TRADES))
{
if((OrderMagicNumber()==Magic)&&(OrderSymbol()==Symbol())&&(OrderType()==OpType))
return(1);
}
}
return(0);
}
//=========================================================================================================================================================================//
void ChartBackground(string StringName,color ImageColor,int Xposition,int Yposition,int Xsize,int Ysize)
{
//---------------------------------------------------------------------
if(ObjectFind(0,StringName)==-1)
{
ObjectCreate(0,StringName,OBJ_RECTANGLE_LABEL,0,0,0,0,0);
ObjectSetInteger(0,StringName,OBJPROP_XDISTANCE,Xposition);
ObjectSetInteger(0,StringName,OBJPROP_YDISTANCE,Yposition);
ObjectSetInteger(0,StringName,OBJPROP_XSIZE,Xsize);
ObjectSetInteger(0,StringName,OBJPROP_YSIZE,Ysize);
ObjectSetInteger(0,StringName,OBJPROP_BGCOLOR,ImageColor);
ObjectSetInteger(0,StringName,OBJPROP_BORDER_TYPE,BORDER_FLAT);
ObjectSetInteger(0,StringName,OBJPROP_BORDER_COLOR,clrBlack);
ObjectSetInteger(0,StringName,OBJPROP_BACK,false);
ObjectSetInteger(0,StringName,OBJPROP_SELECTABLE,false);
ObjectSetInteger(0,StringName,OBJPROP_SELECTED,false);
ObjectSetInteger(0,StringName,OBJPROP_HIDDEN,true);
ObjectSetInteger(0,StringName,OBJPROP_ZORDER,0);
}
//---------------------------------------------------------------------
}
//=========================================================================================================================================================================//
void CommentScreen()
{
//---------------------------------------------------------------------
string MMstring="";
string StrBS;
string StrSS;
string StrBL;
string StrSL;
string StrLot;
//---------------------------------------------------------------------
if(TypeOfLotSize==0)
StrLot="Manually";
if(TypeOfLotSize==1)
StrLot="Automatically";
//---------------------------------------------------------------------
if(PriceOpen_BuyStop==0)
StrBS="Not place Buy Stop";
else
StrBS=DoubleToStr(PriceOpen_BuyStop,Digits);
if(PriceOpen_SellStop==0)
StrSS="Not place Sell Stop";
else
StrSS=DoubleToStr(PriceOpen_SellStop,Digits);
if(PriceOpen_BuyLimit==0)
StrBL="Not place Buy Limit";
else
StrBL=DoubleToStr(PriceOpen_BuyLimit,Digits);
if(PriceOpen_SellLimit==0)
StrSL="Not place Sell Limit";
else
StrSL=DoubleToStr(PriceOpen_SellLimit,Digits);
//---------------------------------------------------------------------
//Comment in chart
Comment("=========================","\n",
WindowExpertName(),"\n",
"=========================","\n",
"Price For Buy Stop: ",StrBS,"\n",
"Price For Sell Stop: ",StrSS,"\n",
"Price For Buy Limit: ",StrBL,"\n",
"Price For Sell Limit: ",StrSL,"\n",
"=========================","\n",
"Orders' Lot Size: ",StrLot," ",DoubleToStr(LotSize,2),"\n",
"=========================");
//---------------------------------------------------------------------
}
//=========================================================================================================================================================================// - #39,425
- Sep 14, 2020 1:18pm Sep 14, 2020 1:18pm
- Joined Apr 2017 | Status: Trader | 1,132 Posts
ook am sorry i dont have the idea about using this "</>" and for what function, thanks for the correction i will use small letters lower case while writing or replying next time thanks
@mntiwana, wooow thank you very, very much Sir, you will increase in blessing, thanks for your help
i dont understand the code but, Sir please i have tested it just now it is still having the same problem
this is what i did i assigned price to all the pending orders and i closed one of them manually, but it did not replace the closed order,
i did something now and it work, i right click, go to properties as if i want to edit, i just click ok and it replace the trade again,
it means without going to click ok it will not replace it, what can be the problem? could it be the sleep in the code?, please i dont mean to ask too much, how to make it replace itself without me going to press ok?
>"
@mntiwana, wooow thank you very, very much Sir, you will increase in blessing, thanks for your help
i dont understand the code but, Sir please i have tested it just now it is still having the same problem
this is what i did i assigned price to all the pending orders and i closed one of them manually, but it did not replace the closed order,
i did something now and it work, i right click, go to properties as if i want to edit, i just click ok and it replace the trade again,
it means without going to click ok it will not replace it, what can be the problem? could it be the sleep in the code?, please i dont mean to ask too much, how to make it replace itself without me going to press ok?
Disliked{quote} Why can't you use code button "</>" for to avoid eating unnecessary space and cluttering thread and small letters (lowercase) as opposed to capital letters that in no way take special consideration and attention but a kind of rude and ..... For example enum MM {Manually_Lot, Automatically_Lot}; //=========================================================================================================================================================================// extern string OpenOrdersSets = "||========== "</Open Orders Sets ==========||";...Ignored
- #39,426
- Sep 14, 2020 1:44pm Sep 14, 2020 1:44pm
- Joined Mar 2013 | Status: Trader | 2,466 Posts
Dislikedook am sorry i dont have the idea about using this "</>" and for what function, thanks for the correction i will use small letters lower case while writing or replying next time thanks @mntiwana, wooow thank you very, very much Sir, you will increase in blessing, thanks for your help i dont understand the code but, Sir please i have tested it just now it is still having the same problem this is what i did i assigned price to all the pending orders and i closed one of them manually, but it did not replace the closed order, i did something now and...Ignored
I am fully poor in coding matters -
but you can post the original code (mq4) not a part of code,so that some kind coder can see and possibly help you
- #39,427
- Sep 14, 2020 1:46pm Sep 14, 2020 1:46pm
Disliked{quote} "CCI experiment" Here is one of so many Mladen's fantastic CCI mt5 ver indicator - of course not alike that but no doubts better than that 22 prices supportive 2 state/type Adaptive 4 types smoothing options an very fine floating level (FL) feature - 2 state/types level option (floating level or quantile level) 3 state color changing options full package alerts but no arrows yet interpolated mtf capable PS : experimenting different setup/s recommended by playing with different parameters {image}{image} {file}Ignored
Thanks a lot Sir. though is different from the conventional type. I will play along with it.
- #39,428
- Edited 2:34pm Sep 14, 2020 2:06pm | Edited 2:34pm
- Joined Apr 2017 | Status: Trader | 1,132 Posts
Disliked{quote} Brother I am fully poor in coding matters -but you can post the original code (mq4) not a part of code,so that some kind coder can see and possibly help you
Ignored
thanks so much for your suggestions and help
Need Help from Coders Please!
I have this indicator which shows Currency & Pairwise information along with MoneyFlow & C07 information
This indicator however does not populate any information in the data window.
I have marked Section A, B & C which I would appreciate if can be transformed into separate indicators which populate relevant information in Data Window.
Would any coder be interested to help?
Regards
Sam
I have this indicator which shows Currency & Pairwise information along with MoneyFlow & C07 information
This indicator however does not populate any information in the data window.
I have marked Section A, B & C which I would appreciate if can be transformed into separate indicators which populate relevant information in Data Window.
Would any coder be interested to help?
Regards
Sam
- #39,430
- Edited 8:22pm Sep 14, 2020 5:33pm | Edited 8:22pm
- Joined Sep 2018 | Status: Trader Man | 2,132 Posts
First I want to thank to everyone who also contributes here.
I am studying this indicator in the renko chart and thought that a captain might also be interested.
These indicators I got here on the forum.
Hello, programmer friends!
I have an indicator and I would like to automate it.
The line crossed above the zero line, close the sale and enter the purchase order.
The line crossed below the zero line, close the purchase and enter the sales order.
Please, you need to work on the Timeless Graph (Grafico Renko).
See explanatory image on Renko's chart
Yellow line Crossed the zero line, so close all orders.
Red Line Crossed the zero line below to open the sale.
Red Line Crossed the zero line above to open the purchase.
I am studying this indicator in the renko chart and thought that a captain might also be interested.
These indicators I got here on the forum.
Attached File(s)
Attached File(s)
Hello, programmer friends!
I have an indicator and I would like to automate it.
The line crossed above the zero line, close the sale and enter the purchase order.
The line crossed below the zero line, close the purchase and enter the sales order.
Please, you need to work on the Timeless Graph (Grafico Renko).
See explanatory image on Renko's chart
Yellow line Crossed the zero line, so close all orders.
Red Line Crossed the zero line below to open the sale.
Red Line Crossed the zero line above to open the purchase.
"No pain no gain"
- #39,431
- Sep 14, 2020 6:23pm Sep 14, 2020 6:23pm
DislikedResp Coders/Friends i am looking for HalfTrend 2 indicator for MT5 . Thanks {image}Ignored
Attached File(s)
1
- #39,432
- Sep 14, 2020 6:56pm Sep 14, 2020 6:56pm
DislikedHello I took this code from mql5 site for(int i=0;i<limit;i++) { ma[i]=iRSI(Symbol(),0,14,0,i); } for(int i=0;i<limit;i++) { ima[i]=iMAOnArray(ma,0,10,0,0,i); } I want to use it in an EA but I get error [- "array required" ma- "parameter conversion not allowed" I'll appreciate any helpIgnored
Inserted Code
double ma[];
double ima[];
if(ArrayResize(ma,limit)<0)
Print(GetLastError());
if(ArrayResize(ima,limit)<0)
Print(GetLastError());
for(int i=0; i<limit; i++)
{ ma[i]=iRSI(Symbol(),0,14,0,i); }
for(int i=0; i<limit; i++)
{ ima[i]=iMAOnArray(ma,0,10,0,0,i); } - #39,433
- Edited 8:15pm Sep 14, 2020 7:38pm | Edited 8:15pm
DislikedPLEASE I NEED HELP!! HIGHLY APPRECIATE YOUR EFFORTS. CAN CODER HELP ME TO MAKE THIS PENDING ORDERS AFTER GET FILLED, STOPLOSS/TAKEPROFIT IMMEDIATELY OPEN ANOTHER PENDING TO REPLACE THE PRICE THAT GOT FILLED, EA WILL ALWAYS CHECK IF PENDING IS PLACED ON SPECIFIED PRICE, IF NONE WILL PLACE ANYONE MISSING, enum MM {Manually_Lot, Automatically_Lot}; //=========================================================================================================================================================================// extern string OpenOrdersSets...Ignored
IMP,
There is bug in your code. The parameter 'SendBS' is always false after pending order.
You should make a void() to check the order. If the order was trigger sl/tp, then the SendBS need to be true.
good luck
Don't Rush Things, Be PATIENT and Wait For the Best Trade Setup
- #39,434
- Sep 14, 2020 8:17pm Sep 14, 2020 8:17pm
- Joined Apr 2017 | Status: Trader | 1,132 Posts
Disliked{quote} Hi, samalin IMP, There is bug in your code. The parameter 'SendBS' is always false after pending order. You should make a void to check the order. If the order was trigger sl/tp, then the SendBS need to be true. good luckIgnored
sincerely i dont understand how you explain me to correct this bug, am not a programmer, i dont know how to make a void to check the order, do you mean i should change the SENDBS to true?
Please is it possible that you directly help me to edit it in the code? please kindly help
i am trying to forward you the code but i dont know this key to minimize the space, and if i paste its too clumsy please can you help to copy edit and post, or tell me how to send you neatly i will send
Disliked{quote} thanks for your concern to help, sincerely i dont understand how you explain me to correct this bug, am not a programmer, i dont know how to make a void to check the order, do you mean i should change the SENDBS to true? Please is it possible that you directly help me to edit it in the code? please kindly help i am trying to forward you the code but i dont know this key to minimize the space, and if i paste its too clumsy please can you help to copy edit and post, or tell me how to send you neatly i will sendIgnored
Don't Rush Things, Be PATIENT and Wait For the Best Trade Setup
- #39,436
- Sep 15, 2020 12:44am Sep 15, 2020 12:44am
- Joined Apr 2017 | Status: Trader | 1,132 Posts
ok thanks i appreciate your time and effort
- #39,437
- Sep 15, 2020 2:32am Sep 15, 2020 2:32am
- | Joined Jul 2012 | Status: Trader | 1,170 Posts
DislikedFirst I want to thank to everyone who also contributes here. I am studying this indicator in the renko chart and thought that a captain might also be interested. These indicators I got here on the forum. {file}{file} Hello, programmer friends! I have an indicator and I would like to automate it. The line crossed above the zero line, close the sale and enter the purchase order. The line crossed below the zero line, close the purchase and enter the sales order. Please, you need to work on the Timeless Graph (Grafico Renko). See explanatory image on...Ignored
- #39,440
- Sep 15, 2020 6:38am Sep 15, 2020 6:38am
- Joined Apr 2017 | Status: Trader | 1,132 Posts
[quote=Cj.cn;13165924]{quote} Pls have a look whether it is what you want. {file}[/
hurrayyy!!! thank you so much is exactly the function that i wanted its working fine, please i dont mean to border you much about this EA but, from what i see you've done in the code, is more than what i thought, i want to use this EA with a fib, i was thinking i will copy and paste but its not the case,
please this last time i need your help, the only way i can complete this strategy is to have 12 functions(6 pairs of buystop/sellstop only) i have multiplied it in the code below but to make it work like yours above is confusing
is it possible to apply the same method of function in the attached file below?
hurrayyy!!! thank you so much is exactly the function that i wanted its working fine, please i dont mean to border you much about this EA but, from what i see you've done in the code, is more than what i thought, i want to use this EA with a fib, i was thinking i will copy and paste but its not the case,
please this last time i need your help, the only way i can complete this strategy is to have 12 functions(6 pairs of buystop/sellstop only) i have multiplied it in the code below but to make it work like yours above is confusing
is it possible to apply the same method of function in the attached file below?
Attached File(s)
228 traders viewing now, 2 are registered: ,