. . . you cannot create it again, it already exists . . . instead check if it exists and if it does don't try and create it again, just move it using ObjectSet()
i can not make a time expiration condition for the price level. as i mention before, if the price stays under LSell or over LBuy for more than 96 candles, to dismiss that price level.
i was trying to use if(Time[high_bar]<Time[96]) && LevelSset=true.... set LevelSset to false... but it seems is not working.... void CkExpLSell ()... i'm sure i'm doing something wrong but... i have no idea what, so help pls :)
//+------------------------------------------------------------------+//| 3expert.mq4 |//| ant |//| |//+------------------------------------------------------------------+#property copyright"ant"#property link""#property indicator_chart_window#property indicator_buffers1#property indicator_color1 Yellow
externbool UseTrigger1=true;
externbool UseTrigger2=true;
externint Kperiod = 80;
externint Dperiod = 30;
externint Stochshift = 30;
externint AddToSL=0;
externint MinSL=50;
externint MaxSL=100;
externint TakeProfit=50;
externint Slippage=0;
externdouble lot=0.10;
int MagicNumber=777;
bool TriggerBuy1=false;
bool TriggerBuy2=false;
bool TriggerSell1=false;
bool TriggerSell2=false;
bool LevelBset=false;
bool LevelSset=false;
double LevelB,LevelS;
double ticketBuy,ticketSell;
double SL,TP;
double stoch;
double LBuy;
double LSell;
int high_bar,low_bar;
bool BarsOnChart;
bool AlternativeEntryB=false;
datetime AlternativeEntryBTime;
bool AlternativeEntryS=false;
datetime AlternativeEntrySTime;
//+------------------------------------------------------------------+//| expert initialization function |//+------------------------------------------------------------------+int init()
{
//----//----return(0);
}
//+------------------------------------------------------------------+//| expert deinitialization function |//+------------------------------------------------------------------+int deinit()
{
//----//----return(0);
}
//+------------------------------------------------------------------+//| expert start function |//+------------------------------------------------------------------+int start()
{
//----
stoch=iStochastic(NULL,0,Kperiod,Dperiod,Stochshift,MODE_SMA,1,MODE_MAIN,0);
SellLevelSet();
CkExpLSell ();
BuyLevelSet();
CkExpLBuy ();
if (LevelSset==true || LevelBset==true)
{
if (IsNewBar ())
{
CheckTrigger();
}
}
//----return(0);
}
//+------------------------------------------------------------------+////////////////////////////IsNewCandle///////////////////////////////bool IsNewBar ()
{
if (Bars==BarsOnChart)
return(false);
BarsOnChart = Bars;
return(true);
}
/////////////////////////////LSell Setup////////////////////////////////void SellLevelSet()
{
if (stoch>75 && LevelSset==false)
{
LSell=High[iHighest(NULL,0,MODE_HIGH,34,2)];
high_bar=iHighest(NULL,0,MODE_HIGH,34,2);
if(Bid<LSell && High[0]<LSell && High[1]<LSell)
{
ObjectCreate("tomato "+Time[0],OBJ_ARROW,0,Time[high_bar],LSell+Point*20);
ObjectSet("tomato "+Time[0],OBJPROP_ARROWCODE,242);
ObjectSet("tomato "+Time[0],OBJPROP_COLOR,Tomato);
LevelSset=true;
Print("LevelSset on "+DoubleToStr(LSell,5));
}
}
}
///////////////////////////////LSellCheckExp/////////////////////////////////void CkExpLSell ()
{
if(LevelSset==true)
{
if(Close[2]>LSell && Close[1]>LSell) //LSell expires after two bars close over
{
LevelSset=false;
Print (DoubleToStr(LSell,5)+" expired - close");
}
if(Time[high_bar]<Time[96]) //LSell expires after 96 bars
{
LevelSset=false;
Print (DoubleToStr(LSell,5)+" expired - time");
}
}
}
/////////////////////////////LBuy Setup////////////////////////////////void BuyLevelSet()
{
if (stoch<25 && LevelBset==false)
{
LBuy=Low[iLowest(NULL,0,MODE_HIGH,34,2)];
low_bar=iLowest(NULL,0,MODE_HIGH,34,2);
if(Bid>LBuy && Low[0]>LBuy && Low[1]>LBuy)
{
ObjectCreate("olive "+Time[0],OBJ_ARROW,0,Time[low_bar],LBuy-Point*20);
ObjectSet("olive "+Time[0],OBJPROP_ARROWCODE,241);
ObjectSet("olive "+Time[0],OBJPROP_COLOR,Olive);
LevelBset=true;
Print("LevelBset on "+DoubleToStr(LBuy,5));
}
}
}
///////////////////////////////LBuyCheckExp/////////////////////////////////void CkExpLBuy ()
{
if(LevelBset==true)
{
if(Close[2]<LBuy && Close[1]<LBuy)
{
LevelBset=false;
Print (DoubleToStr(LBuy,5)+" expired - close");
}
}
}
//////////////////////CHECK TRIGGER/////////////////////void CheckTrigger()
{
//Trigger1if (UseTrigger1)
{
if (Low[2]>LBuy && Low[1]<LBuy && Close[1]>LBuy)
{
TriggerBuy1=true;
Alert("Tbuy1 ON");
}
else
TriggerBuy1=false;
if (High[2]<LSell && High[1]>LSell && Close[1]<LSell)
{
TriggerSell1=true;
Alert("TSeLL1 ON");
}
else
TriggerSell1=false;
}
else
{
TriggerBuy1=false;
TriggerSell1=false;
}
//Trigger2 if (UseTrigger2)
{
if (Low[3]>LBuy && Low[2]<LBuy && Close[2]<LBuy && Close[1]>LBuy)
{
TriggerBuy2=true;
Alert("Tbuy2 ON");
}
else
TriggerBuy2=false;
if (High[3]<LSell && High[2]>LSell && Close[2]>LSell && Close[1]<LSell)
TriggerSell2=true;
else
TriggerSell2=false;
}
else
{
TriggerBuy2=false;
TriggerSell2=false;
}
CheckOpen();
}
//////////////////////////////////CheckOpen///////////////////////////////////void CheckOpen()
{
if (TriggerBuy1)
{
SL=Low[1]-AddToSL*Point;
if ( (Open[0]-SL)/Point<=MaxSL && (Open[0]-SL)/Point>=MinSL)
{
Print("Trigger1: SL" +DoubleToStr(SL,0)+ "under"+ DoubleToStr(MaxSL,0)+ " pips");
OpenTrade(1,"Trigger1");
}
if ( (Open[0]-SL)/Point<=MaxSL && (Open[0]-SL)/Point<MinSL)
{
SL=Open[0]-MinSL*Point;
Print("Trigger1: SL minimum"+ DoubleToStr(MinSL,0)+ "pips, SL="+DoubleToStr(SL,5));
OpenTrade(1,"Trigger1");
}
if ( (Open[0]-SL)/Point>MaxSL)
{
Print("Trigger1: SL not taken because difference is ",DoubleToStr((Open[0]-SL)/Point,0));
AlternativeEntryB=true;
AlternativeEntryBTime=Time[0];
}
}
if (TriggerSell1)
{
SL=High[1]+AddToSL*Point;
SL=SL+MathAbs(Ask-Bid);
if ( (SL-Open[0])/Point<=MaxSL && (SL-Open[0])/Point>=MinSL)
{
Print("Trigger1: SL"+ DoubleToStr(SL,0)+ "under"+ DoubleToStr(MaxSL,0)+ "pips");
OpenTrade(2,"Trigger1");
}
if ( (SL-Open[0])/Point<=MaxSL && (SL-Open[0])/Point<MinSL)
{
SL=Open[0]+MinSL*Point+MathAbs(Ask-Bid);
Print("Trigger1: SL minimum"+ DoubleToStr(MinSL,0)+ "pips, SL="+DoubleToStr(SL,5));
OpenTrade(2,"Trigger1");
}
if ( (SL-Open[0])/Point<=MaxSL)
{
Print("Trigger1: SL not taken because difference is ",DoubleToStr((SL-Open[0])/Point,0));
AlternativeEntryS=true;
AlternativeEntrySTime=Time[0];
}
}
if (TriggerBuy2)
{
SL=Low[iLowest(NULL,0,MODE_LOW,3,1)]-AddToSL*Point;
if ( (Open[0]-SL)/Point<=MaxSL && (Open[0]-SL)/Point>=MinSL)
{
Print("Trigger2: SL"+ DoubleToStr(SL,0)+ "under"+ DoubleToStr(MaxSL,0)+ "pips");
OpenTrade(1,"Trigger2");
}
if ( (Open[0]-SL)/Point<=MaxSL && (Open[0]-SL)/Point<MinSL)
{
SL=Open[0]-MinSL*Point;
Print("Trigger2: SL minimum"+ DoubleToStr(MinSL,0)+ " pips, SL="+DoubleToStr(SL,5));
OpenTrade(1,"Trigger2");
}
if ( (Open[0]-SL)/Point>MaxSL)
{
Print("Trigger2: SL not taken because difference is ",DoubleToStr((Open[0]-SL)/Point,0));
AlternativeEntryB=true;
AlternativeEntryBTime=Time[0];
}
}
if (TriggerSell2)
{
SL=High[iHighest(NULL,0,MODE_HIGH,3,1)]+AddToSL*Point;
SL=SL+MathAbs(Ask-Bid);
if ( (SL-Open[0])/Point<=MaxSL && (SL-Open[0])/Point>=MinSL)
{
Print("Trigger2: SL"+ DoubleToStr(SL,0)+ "under"+ DoubleToStr(MaxSL,0)+ "pips");
OpenTrade(2,"Trigger2");
}
if ( (SL-Open[0])/Point<=MaxSL && (SL-Open[0])/Point<MinSL)
{
SL=Open[0]+MinSL*Point+MathAbs(Ask-Bid);
Print("Trigger2: SL minimum"+ DoubleToStr(MinSL,0)+ "pips, SL="+DoubleToStr(SL,5));
OpenTrade(2,"Trigger2");
}
if ( (SL-Open[0])/Point<=MaxSL)
{
Print("Trigger2: SL not taken because difference is ",DoubleToStr((SL-Open[0])/Point,0));
AlternativeEntryS=true;
AlternativeEntrySTime=Time[0];
}
}
}
//////////////////////////////////////////Open Trade//////////////////////////////////////////////void OpenTrade(int dir,string trigger)
{
ticketBuy=0;
ticketSell=0;
if (dir==1)
{
Print(trigger, " - Opening BUY");
TP=Ask+TakeProfit*Point;
ticketBuy=OrderSend(Symbol(),OP_BUY,lot,Ask,Slippage,SL,TP,trigger,MagicNumber,0,Blue);
}
if (dir==2)
{
Print(trigger, " - Opening SELL");
TP=Bid-TakeProfit*Point;
ticketSell=OrderSend(Symbol(),OP_SELL,lot,Bid,Slippage,SL,TP,trigger,MagicNumber,0,Red);
}
if (ticketBuy>0)
{
Print("Deleting - Buy Level", DoubleToStr(LBuy,5));
LevelBset=false;
}
if (ticketSell>0)
{
Print("Deleting - Sell Level", DoubleToStr(LSell,5));
LevelSset=false;
}
}
i can not make a time expiration condition for the price level. as i mention before, if the price stays under LSell or over LBuy for more than 96 candles, to dismiss that price level.
i was trying to use if(Time[high_bar]<Time[96]) && LevelSset=true.... set LevelSset to false... but it seems is not working.... void CkExpLSell ()... i'm sure i'm doing something wrong but... i have no idea what, so help pls :)
ObjectCreate("olive "+Time[0]
the name of the line is telling you moment it is created
i have given you in this topic already how to check using the name of the line the way to check for time expiration
int Bar96 = 96 * Period() * 60;
:
if (Time[0] - Bar96 > SetBar && ObjectGet(Name, OBJPROP_ARROWCODE) == 242)
This assumes that there are no missing bars on the chart, like M1 has when there are no ticks in a minute, or all TFs less than weekly over the week end. Don't Assume, simplify:
96 bars ago
// int Bar96 = 96 * Period() * 60;
:
if (Time[96] > SetBar && ObjectGet(Name, OBJPROP_ARROWCODE) == 242)
on strategy tester things look ok. then i put the ea on different platforms demo accounts and it worked (setting price lvls and making trades as expected) until this error appeared.
i change the testing period in strategy tester and i got the same error... it doesn't matter if it is a LevelBset or LevelSset the ea is setting the level at the correct price, then the price level is modify to 0.0000.
i didnt find the mistake till now, so please check my code.
thank you for your help.
//+------------------------------------------------------------------+//| 3expert.mq4 |//| ant |//| |//+------------------------------------------------------------------+#property copyright"ant"#property link""externbool UseTrigger1=true;
externbool UseTrigger2=true;
externint Kperiod = 80;
externint Dperiod = 30;
externint Stochshift = 30;
externint AddToSL=0;
externint MinSL=50;
externint MaxSL=100;
externint TakeProfit=50;
externint Slippage=0;
externdouble lot=1;
int MagicNumber=777;
/*extern int Startday=1;
extern int Starthour=0;
extern int Startminute=30;
extern int Endday=5;
extern int Endhour=20;
extern int Closehour=20;
bool Weekend=false;*/bool TriggerBuy1=false;
bool TriggerBuy2=false;
bool TriggerSell1=false;
bool TriggerSell2=false;
bool LevelBset=false;
bool LevelSset=false;
double LevelB,LevelS;
double ticketBuy,ticketSell;
double SL,TP;
double stoch;
double LBuy;
double LSell;
int high_bar,low_bar;
bool AlternativeEntryB=false;
datetime AlternativeEntryBTime;
bool AlternativeEntryS=false;
datetime AlternativeEntrySTime;
//+------------------------------------------------------------------+//| expert initialization function |//+------------------------------------------------------------------+int init()
{
//----//----return(0);
}
//+------------------------------------------------------------------+//| expert deinitialization function |//+------------------------------------------------------------------+int deinit()
{
//----//----return(0);
}
//+------------------------------------------------------------------+//| expert start function |//+------------------------------------------------------------------+int start()
{
//if (TradingHours())if (WeClose())
return (0);
stoch=iStochastic(NULL,0,Kperiod,Dperiod,Stochshift,MODE_SMA,1,MODE_MAIN,0);
SellLevelSet();
BuyLevelSet();
if (OrdersTotal()==0)
{
CheckRecoveryTrade();
CheckAlternativeEntry();
}
if (LevelSset==true || LevelBset==true)
{
if (IsNewBar ())
{
CkExpLSell ();
CkExpLBuy ();
CkExpTime();
CheckTrigger();
}
}
//----return(0);
}
//+------------------------------------------------------------------+////////////////////////////TradingHours//////////////////////////////bool WeClose ()
{
if (DayOfWeek()==0 || DayOfWeek()==6)
{ LevelSset=false;
del242();
LevelBset=false;
del241();
return (true);
}
else
{return (false);}
}
////////////////////////////IsNewCandle///////////////////////////////bool IsNewBar ()
{
int BarsOnChart;
if (Bars==BarsOnChart)
return(false);
BarsOnChart = Bars;
return(true);
}
/////////////////////////////LSell Setup////////////////////////////////void SellLevelSet()
{
if (stoch>75 && LevelSset==false)
{
LSell=High[iHighest(NULL,0,MODE_HIGH,34,2)];
high_bar=iHighest(NULL,0,MODE_HIGH,34,2);
if(Bid<LSell && High[0]<LSell && High[1]<LSell)
{
if(Time[high_bar]>TimeCurrent()-10800)
{
ObjectCreate("tomato "+Time[high_bar],OBJ_ARROW,0,Time[high_bar],LSell+Point*20);
ObjectSet("tomato "+Time[high_bar],OBJPROP_ARROWCODE,242);
ObjectSet("tomato "+Time[high_bar],OBJPROP_COLOR,Tomato);
LevelSset=true;
Print("LevelSset on "+DoubleToStr(LSell,5));
}
}
}
}
///////////////////////////////Object Delete////////////////////////////////void del242 ()
{
string Name;
double SetBar;
for(int i = 0; i < ObjectsTotal(); i++)
{
Name=ObjectName(i);
SetBar = ObjectGet(Name, OBJPROP_TIME1);
if(ObjectGet(Name, OBJPROP_ARROWCODE) == 242)
{
ObjectDelete(Name);
}
}
}
void del241 ()
{
string Name;
double SetBar;
for(int i = 0; i < ObjectsTotal(); i++)
{
Name=ObjectName(i);
SetBar = ObjectGet(Name, OBJPROP_TIME1);
if(ObjectGet(Name, OBJPROP_ARROWCODE) == 241)
{
ObjectDelete(Name);
}
}
}
///////////////////////////////LSellCheckExp/////////////////////////////////void CkExpLSell ()
{
if(Close[2]>LSell && Close[1]>LSell) //LSell expires after two bars close over
{
LevelSset=false;
Print (DoubleToStr(LSell,5)+" expired - close");
del242 ();
}
}
////////////////////////////////96BarExp//////////////////////////////void CkExpTime ()
{
int Bar96 = iBarShift(NULL,0,Time[0]-96*Period()*60);
string Name;
double SetBar;
for(int i = 0; i < ObjectsTotal(); i++)
{
Name=ObjectName(i);
SetBar = ObjectGet(Name, OBJPROP_TIME1);
if (Time[Bar96] > SetBar && ObjectGet(Name, OBJPROP_ARROWCODE) == 242)
{
LevelSset = false;
Print (DoubleToStr(LSell,5)+" expired - time");
ObjectDelete(Name);
}
if (Time[Bar96] > SetBar && ObjectGet(Name, OBJPROP_ARROWCODE) == 241)
{
LevelBset = false;
Print (DoubleToStr(LBuy,5)+" expired - time");
ObjectDelete(Name);
}
}
}
/////////////////////////////LBuy Setup////////////////////////////////void BuyLevelSet()
{
if (stoch<25 && LevelBset==false)
{
LBuy=Low[iLowest(NULL,0,MODE_LOW,34,2)];
low_bar=iLowest(NULL,0,MODE_LOW,34,2);
if(Bid>LBuy && Low[0]>LBuy && Low[1]>LBuy)
{
if(Time[low_bar]>TimeCurrent()-10800)
{
ObjectCreate("olive "+Time[low_bar],OBJ_ARROW,0,Time[low_bar],LBuy-Point*20);
ObjectSet("olive "+Time[low_bar],OBJPROP_ARROWCODE,241);
ObjectSet("olive "+Time[low_bar],OBJPROP_COLOR,Olive);
LevelBset=true;
Print("LevelBset on "+DoubleToStr(LBuy,5));
}
}
}
}
///////////////////////////////LBuyCheckExp/////////////////////////////////void CkExpLBuy ()
{
if(Close[2]<LBuy && Close[1]<LBuy)
{
LevelBset=false;
Print (DoubleToStr(LBuy,5)+" expired - close");
del241();
}
}
//////////////////////CHECK TRIGGER/////////////////////void CheckTrigger()
{
//Trigger1if (UseTrigger1)
{
if (Low[2]>LBuy && Low[1]<LBuy && Close[1]>LBuy)
{
TriggerBuy1=true;
Print("Tbuy1 ON");
del241();
}
else
TriggerBuy1=false;
if (High[2]<LSell && High[1]>LSell && Close[1]<LSell)
{
TriggerSell1=true;
Print("TSeLL1 ON");
del242();
}
else
TriggerSell1=false;
}
else
{
TriggerBuy1=false;
TriggerSell1=false;
}
//Trigger2 if (UseTrigger2)
{
if (Low[3]>LBuy && Low[2]<LBuy && Close[2]<LBuy && Close[1]>LBuy)
{
TriggerBuy2=true;
Print("Tbuy2 ON");
del241();
}
else
TriggerBuy2=false;
if (High[3]<LSell && High[2]>LSell && Close[2]>LSell && Close[1]<LSell)
{
TriggerSell2=true;
Print("TSeLL2 ON");
del242();
}
else
TriggerSell2=false;
}
else
{
TriggerBuy2=false;
TriggerSell2=false;
}
CheckOpen();
}
//////////////////////////////////CheckOpen///////////////////////////////////void CheckOpen()
{
if (TriggerBuy1)
{
SL=Low[1]-AddToSL*Point;
if ( (Ask-SL)/Point<=MaxSL && (Ask-SL)/Point>=MinSL)
{
Print("Trigger1: SL" +DoubleToStr(SL,0)+ "under"+ DoubleToStr(MaxSL,0)+ " pips");
OpenTrade(1,"Trigger1");
}
if ( (Ask-SL)/Point<=MaxSL && (Ask-SL)/Point<MinSL)
{
SL=Ask-MinSL*Point;
Print("Trigger1: SL minimum "+ DoubleToStr(MinSL,0)+ " pips, SL="+DoubleToStr(SL,5));
OpenTrade(1,"Trigger1");
}
if ( (Ask-SL)/Point>MaxSL)
{
Print("Trigger1: SL not taken because difference is ",DoubleToStr((Open[0]-SL)/Point,0));
AlternativeEntryB=true;
AlternativeEntryBTime=Time[0];
}
}
if (TriggerSell1)
{
SL=High[1]+AddToSL*Point;
SL=SL+MathAbs(Ask-Bid);
if ( (SL-Open[0])/Point<=MaxSL && (SL-Open[0])/Point>=MinSL)
{
Print("Trigger1: SL"+ DoubleToStr(SL,0)+ "under"+ DoubleToStr(MaxSL,0)+ "pips");
OpenTrade(2,"Trigger1");
}
if ( (SL-Open[0])/Point<=MaxSL && (SL-Open[0])/Point<MinSL)
{
SL=Open[0]+MinSL*Point;
Print("Trigger1: SL minimum"+ DoubleToStr(MinSL,0)+ "pips, SL="+DoubleToStr(SL,5));
OpenTrade(2,"Trigger1");
}
if ( (SL-Open[0])/Point>MaxSL)
{
Print("Trigger1: SL not taken because difference is ",DoubleToStr((SL-Open[0])/Point,0));
AlternativeEntryS=true;
AlternativeEntrySTime=Time[0];
}
}
if (TriggerBuy2)
{
SL=Low[iLowest(NULL,0,MODE_LOW,3,1)]-AddToSL*Point;
if ( (Ask-SL)/Point<=MaxSL && (Ask-SL)/Point>=MinSL)
{
Print("Trigger2: SL"+ DoubleToStr(SL,0)+ "under"+ DoubleToStr(MaxSL,0)+ "pips");
OpenTrade(1,"Trigger2");
}
if ( (Ask-SL)/Point<=MaxSL && (Ask-SL)/Point<MinSL)
{
SL=Open[0]+MathAbs(Ask-Bid)-MinSL*Point;
Print("Trigger2: SL minimum "+ DoubleToStr(MinSL,0)+ " pips, SL="+DoubleToStr(SL,5));
OpenTrade(1,"Trigger2");
}
if ( (Ask-SL)/Point>MaxSL)
{
Print("Trigger2: SL not taken because difference is ",DoubleToStr((Open[0]-SL)/Point,0));
AlternativeEntryB=true;
AlternativeEntryBTime=Time[0];
}
}
if (TriggerSell2)
{
SL=High[iHighest(NULL,0,MODE_HIGH,3,1)]+AddToSL*Point;
SL=SL+MathAbs(Ask-Bid);
if ( (SL-Open[0])/Point<=MaxSL && (SL-Open[0])/Point>=MinSL)
{
Print("Trigger2: SL"+ DoubleToStr(SL,0)+ "under"+ DoubleToStr(MaxSL,0)+ "pips");
OpenTrade(2,"Trigger2");
}
if ( (SL-Open[0])/Point<=MaxSL && (SL-Open[0])/Point<MinSL)
{
SL=Open[0]+MinSL*Point;
Print("Trigger2: SL minimum"+ DoubleToStr(MinSL,0)+ "pips, SL="+DoubleToStr(SL,5));
OpenTrade(2,"Trigger2");
}
if ( (SL-Open[0])/Point>MaxSL)
{
Print("Trigger2: SL not taken because difference is ",DoubleToStr((SL-Open[0])/Point,0));
AlternativeEntryS=true;
AlternativeEntrySTime=Time[0];
}
}
}
//////////////////////////////////////////Open Trade//////////////////////////////////////////////void OpenTrade(int dir,string trigger)
{
ticketBuy=0;
ticketSell=0;
if (OrdersTotal()==0)
{
if (dir==1)
{
Print(trigger, " - Opening BUY");
TP=Ask+TakeProfit*Point;
ticketBuy=OrderSend(Symbol(),OP_BUY,lot,Ask,Slippage,SL,TP,trigger,MagicNumber,0,Blue);
}
if (dir==2)
{
Print(trigger, " - Opening SELL");
TP=Bid-TakeProfit*Point;
ticketSell=OrderSend(Symbol(),OP_SELL,lot,Bid,Slippage,SL,TP,trigger,MagicNumber,0,Red);
}
if (ticketBuy>0)
{
Print("Deleting - Buy Level", DoubleToStr(LBuy,5));
LevelBset=false;
}
if (ticketSell>0)
{
Print("Deleting - Sell Level", DoubleToStr(LSell,5));
LevelSset=false;
}
}
}
///////////////////////////CHECK ALTERNATIVE ENTRY////////////////////////////void CheckAlternativeEntry()
{
if (AlternativeEntryB)
{
if (Time[0]-AlternativeEntryBTime>=Time[0]-Time[17])
{
AlternativeEntryB=false;
del241();
}
}
if (AlternativeEntryS)
{
if (Time[0]-AlternativeEntrySTime>=Time[0]-Time[17])
{
AlternativeEntryS=false;
del242();
}
}
if (AlternativeEntryB)
{
if ( (Ask-SL) /Point<=70)
{
Print("Trigger: SL under 7 pips");
OpenTrade(1,"Trigger");
AlternativeEntryB=false;
}
}
if (AlternativeEntryS)
{
if( (SL-Bid) /Point<=70)
{
Print("Trigger: SL under 7 pips");
OpenTrade(2,"Trigger");
AlternativeEntryS=false;
}
}
}
////////////////////////////CHECK RECOVERY TRADE/////////////////////void CheckRecoveryTrade()
{
OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY);
double Loss=MathAbs(OrderOpenPrice()-OrderClosePrice());
if (OrderStopLoss()==OrderClosePrice())
{
if (OrderCloseTime()<Time[0] && OrderCloseTime()>=Time[1])
{
if (OrderType()==OP_BUY)
{
if (Close[1]>OrderStopLoss())
{
SL=Low[1]-AddToSL*Point;
if ((Ask-SL)/Point<=100)
{
Print("Recovery BUY");
TP=Ask+Loss;
OrderSend(Symbol(),OP_BUY,lot,Ask,Slippage,SL,TP,"recovery",MagicNumber,0,Olive);
}
}
}
if (OrderType()==OP_SELL)
{
if (Close[1]<OrderStopLoss())
{
SL=High[1]+AddToSL*Point;
SL=SL+MathAbs(Ask-Bid);
if( (SL-Open[0])/Point<=100)
{
Print("Recovery SELL");
TP=Bid-Loss;
OrderSend(Symbol(),OP_SELL,lot,Bid,Slippage,SL,TP,"recovery",MagicNumber,0,Pink);
}
}
}
}
}
}
some ideas, what is wrong... anyone ?
thank you
Once you create an object . . .
. . . you cannot create it again, it already exists . . . instead check if it exists and if it does don't try and create it again, just move it using ObjectSet()
i used a different name for each candle so it was no problem with the object.
i rewrite it like this and now works perfect:
sets a sell level, and if i get two closes over that level -> LevelSset=false -> starts searching for next LSell.
hi, need some help.
i can not make a time expiration condition for the price level. as i mention before, if the price stays under LSell or over LBuy for more than 96 candles, to dismiss that price level.
i was trying to use if(Time[high_bar]<Time[96]) && LevelSset=true.... set LevelSset to false... but it seems is not working.... void CkExpLSell ()... i'm sure i'm doing something wrong but... i have no idea what, so help pls :)
hi, need some help.
i can not make a time expiration condition for the price level. as i mention before, if the price stays under LSell or over LBuy for more than 96 candles, to dismiss that price level.
i was trying to use if(Time[high_bar]<Time[96]) && LevelSset=true.... set LevelSset to false... but it seems is not working.... void CkExpLSell ()... i'm sure i'm doing something wrong but... i have no idea what, so help pls :)
the name of the line is telling you moment it is created
i have given you in this topic already how to check using the name of the line the way to check for time expiration
and i don't see you are using that method !!
Your indicator can't do tradingfunctions !!!!!!!!........
Make an EA if you do OrderSend
the name of the line is telling you moment it is created
i have given you in this topic already how to check using the name of the line the way to check for time expiration
and i don't see you are using that method !!
@ deVries ObjectGet(Name, OBJPROP_TIME1) is even better, no need for unnecessary code (StringSubstr() StrToTime())
hi guys,
on strategy tester things look ok. then i put the ea on different platforms demo accounts and it worked (setting price lvls and making trades as expected) until this error appeared.
i change the testing period in strategy tester and i got the same error... it doesn't matter if it is a LevelBset or LevelSset the ea is setting the level at the correct price, then the price level is modify to 0.0000.
i didnt find the mistake till now, so please check my code.
thank you for your help.