You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Kikousi,
You may want to test for yourself the best coordinates. FerruFX and CJA have used the best solutions of having default corner positions with user-inputs to object placement. You may also want to look at OBJPROP_CORNER
Also, please try not to post the same request as you have done. Users see your post, and if someone can help you they will.
Thank you
Edit: Using the corner property 0 is upper left, 1 is upper right, 2 lower left, 3 lower right. It is 0 count.
Help with debugging my EA
Hi. Sorry if this is the wrong forum to post and please fix if it is.
I programmed my own EA and have some problems with order filling and stop loss orders. Could somebody help? I can share the EA.
Thanks
codobro,
Thank you very much for your kind reply.
I will not post the same question again from now on.
I apprciate your suggestion.
In this connection, I understand that upper left position is (0,0) , then What is the indication of lower right at that time?
For example, can I use (250,350) for lower right indication when upper left position is (0,0) ?
I thank you in advance for your kindest understanding of the above.
Indicator graph not showing all data
Hi
I am fairly good at C-programming, but starting with MQL4.
I just made my first indicator and it shows an array partly in the separate window.
By partly I mean if you scroll left, then for some time-periods nothing is displayed, and if I scroll further left, then data i displayed for some periods and so on.
If you scroll right, then the same time-periods does not show.
Otherwise I see no pattern.
Also, if I shift from 1-min, where I do see some data, to say 5-min, then nothing are shown at all.
Why isnt all of the data shown? What might I have missed?
Good EA - NEED HELP
Hai,
Is there anyone in this great forum, could modified this EA without any stop loss.
Thanks
//---- input parameters ---------------------------------------------+
extern int INCREMENT=35;
extern double LOTS=0.1;
extern int LEVELS=3;
extern double MAX_LOTS=99;
extern int MAGIC=1803;
extern bool CONTINUE=true;
extern bool MONEY_MANAGEMENT=false;
extern int RISK_RATIO=2;
//+------------------------------------------------------------------+
bool UseProfitTarget=false;
bool UsePartialProfitTarget=false;
int Target_Increment = 50;
int First_Target = 20;
bool UseEntryTime=false;
int EntryTime=0;
//+------------------------------------------------------------------+
bool Enter=true;
int nextTP;
int init()
{
//+------------------------------------------------------------------+
nextTP = First_Target;
//+------------------------------------------------------------------+
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int ticket, cpt, profit, total=0, BuyGoalProfit, SellGoalProfit, PipsLot;
double ProfitTarget=INCREMENT*2, BuyGoal=0, SellGoal=0, spread=(Ask-Bid)/Point, InitialPrice=0;
//----
if(INCREMENT<MarketInfo(Symbol(),MODE_STOPLEVEL)+spread) INCREMENT=1+MarketInfo(Symbol(),MODE_STOPLEVEL)+spread;
if(MONEY_MANAGEMENT) LOTS=NormalizeDouble(AccountBalance()*AccountLeverage()/1000000*RISK_RATIO,0)*MarketInfo(Symbol(),MODE_MINLOT);
if(LOTS<MarketInfo(Symbol(),MODE_MINLOT))
{
Comment("Not Enough Free Margin to begin");
return(0);
}
for(cpt=1;cpt<LEVELS;cpt++) PipsLot+=cpt*INCREMENT;
for(cpt=0;cpt<OrdersTotal();cpt++)
{
OrderSelect(cpt,SELECT_BY_POS,MODE_TRADES);
if(OrderMagicNumber()==MAGIC && OrderSymbol()==Symbol())
{
total++;
if(!InitialPrice) InitialPrice=StrToDouble(OrderComment());
if(UsePartialProfitTarget && UseProfitTarget && OrderType()<2)
{
double val=getPipValue(OrderOpenPrice(),OrderType());
takeProfit(val,OrderTicket());
}
}
}
if(total<1 && Enter && (!UseEntryTime || (UseEntryTime && Hour()==EntryTime)))
{
if(AccountFreeMargin()<(100*LOTS))
{
Print("Not enough free margin to begin");
return(0);
}
// - Open Check - Start Cycle
InitialPrice=Ask;
SellGoal=InitialPrice-(LEVELS+1)*INCREMENT*Point;
BuyGoal=InitialPrice+(LEVELS+1)*INCREMENT*Point;
for(cpt=1;cpt<=LEVELS;cpt++)
{
OrderSend(Symbol(),OP_BUYSTOP,LOTS,InitialPrice+cpt*INCREMENT*Point,2,SellGoal,BuyGoal,DoubleToStr(InitialPrice,MarketInfo(Symbol(),MODE_DIGITS)),MAGIC,0);
OrderSend(Symbol(),OP_SELLSTOP,LOTS,InitialPrice-cpt*INCREMENT*Point,2,BuyGoal+spread*Point,SellGoal+spread*Point,DoubleToStr(InitialPrice,MarketInfo(Symbol(),MODE_DIGITS)),MAGIC,0);
}
} // initial setup done - all channels are set up
else // We have open Orders
{
BuyGoal=InitialPrice+INCREMENT*(LEVELS+1)*Point;
SellGoal=InitialPrice-INCREMENT*(LEVELS+1)*Point;
total=OrdersHistoryTotal();
for(cpt=0;cpt<total;cpt++)
{
OrderSelect(cpt,SELECT_BY_POS,MODE_HISTORY);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC && StrToDouble(OrderComment())==InitialPrice){EndSession();return(0);}
}
if(UseProfitTarget && CheckProfits(LOTS,OP_SELL,true,InitialPrice)>ProfitTarget) {EndSession();return(0);}
BuyGoalProfit=CheckProfits(LOTS,OP_BUY,false,InitialPrice);
SellGoalProfit=CheckProfits(LOTS,OP_SELL,false,InitialPrice);
if(BuyGoalProfit<ProfitTarget)
// - Incriment Lots Buy
{
for(cpt=LEVELS;cpt>=1 && BuyGoalProfit<ProfitTarget;cpt--)
{
if(Ask<=(InitialPrice+(cpt*INCREMENT-MarketInfo(Symbol(),MODE_STOPLEVEL))*Point))
{
ticket=OrderSend(Symbol(),OP_BUYSTOP,cpt*LOTS,InitialPrice+cpt*INCREMENT*Point,2,SellGoal,BuyGoal,DoubleToStr(InitialPrice,MarketInfo(Symbol(),MODE_DIGITS)),MAGIC,0);
}
if(ticket>0) BuyGoalProfit+=LOTS*(BuyGoal-InitialPrice-cpt*INCREMENT*Point)/Point;
}
}
if(SellGoalProfit<ProfitTarget)
// - Increment Lots Sell
{
for(cpt=LEVELS;cpt>=1 && SellGoalProfit<ProfitTarget;cpt--)
{
if(Bid>=(InitialPrice-(cpt*INCREMENT-MarketInfo(Symbol(),MODE_STOPLEVEL))*Point))
{
ticket=OrderSend(Symbol(),OP_SELLSTOP,cpt*LOTS,InitialPrice-cpt*INCREMENT*Point,2,BuyGoal+spread*Point,SellGoal+spread*Point,DoubleToStr(InitialPrice,MarketInfo(Symbol(),MODE_DIGITS)),MAGIC,0);
}
if(ticket>0) SellGoalProfit+=LOTS*(InitialPrice-cpt*INCREMENT*Point-SellGoal-spread*Point)/Point;
}
}
}
//+------------------------------------------------------------------+
Comment("mGRID EXPERT ADVISOR ver 2.0\n",
"FX Acc Server:",AccountServer(),"\n",
"Date: ",Month(),"-",Day(),"-",Year()," Server Time: ",Hour(),":",Minute(),":",Seconds(),"\n",
"Minimum Lot Sizing: ",MarketInfo(Symbol(),MODE_MINLOT),"\n",
"Account Balance: $",AccountBalance(),"\n",
"Symbol: ", Symbol(),"\n",
"Price: ",NormalizeDouble(Bid,4),"\n",
"Pip Spread: ",MarketInfo("EURUSD",MODE_SPREAD),"\n",
"Increment=" + INCREMENT,"\n",
"Lots: ",LOTS,"\n",
"Levels: " + LEVELS,"\n");
return(0);
}
//+------------------------------------------------------------------+
int CheckProfits(double LOTS, int Goal, bool Current, double InitialPrice)
{
int profit=0, cpt;
if(Current)//return current profit
{
for(cpt=0;cpt<OrdersTotal();cpt++)
{
OrderSelect(cpt, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol() && StrToDouble(OrderComment())==InitialPrice)
{
if(OrderType()==OP_BUY) profit+=(Bid-OrderOpenPrice())/Point*OrderLots()/LOTS;
if(OrderType()==OP_SELL) profit+=(OrderOpenPrice()-Ask)/Point*OrderLots()/LOTS;
}
}
return(profit);
}
else
{
if(Goal==OP_BUY)
{
for(cpt=0;cpt<OrdersTotal();cpt++)
{
OrderSelect(cpt, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol() && StrToDouble(OrderComment())==InitialPrice)
{
if(OrderType()==OP_BUY) profit+=(OrderTakeProfit()-OrderOpenPrice())/Point*OrderLots()/LOTS;
if(OrderType()==OP_SELL) profit-=(OrderStopLoss()-OrderOpenPrice())/Point*OrderLots()/LOTS;
if(OrderType()==OP_BUYSTOP) profit+=(OrderTakeProfit()-OrderOpenPrice())/Point*OrderLots()/LOTS;
}
}
return(profit);
}
else
{
for(cpt=0;cpt<OrdersTotal();cpt++)
{
OrderSelect(cpt, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol() && StrToDouble(OrderComment())==InitialPrice)
{
if(OrderType()==OP_BUY) profit-=(OrderOpenPrice()-OrderStopLoss())/Point*OrderLots()/LOTS;
if(OrderType()==OP_SELL) profit+=(OrderOpenPrice()-OrderTakeProfit())/Point*OrderLots()/LOTS;
if(OrderType()==OP_SELLSTOP) profit+=(OrderOpenPrice()-OrderTakeProfit())/Point*OrderLots()/LOTS;
}
}
return(profit);
}
}
}
bool EndSession()
{
int cpt, total=OrdersTotal();
for(cpt=0;cpt<total;cpt++)
{
Sleep(3000);
OrderSelect(cpt,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderType()>1) OrderDelete(OrderTicket());
else if(OrderSymbol()==Symbol() && OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),Bid,3);
else if(OrderSymbol()==Symbol() && OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),Ask,3);
}
if(!CONTINUE) Enter=false;
return(true);
}
double getPipValue(double ord,int dir)
{
double val;
RefreshRates();
if(dir == 1) val=(NormalizeDouble(ord,Digits) - NormalizeDouble(Ask,Digits));
else val=(NormalizeDouble(Bid,Digits) - NormalizeDouble(ord,Digits));
val = val/Point;
return(val);
}
//========== FUNCTION takeProfit
void takeProfit(int current_pips, int ticket)
{
if(OrderSelect(ticket, SELECT_BY_TICKET))
{
if(current_pips >= nextTP && current_pips < (nextTP + Target_Increment))
{
if(OrderType()==1)
{
if(OrderClose(ticket, MAX_LOTS, Ask, 3))
nextTP+=Target_Increment;
else
Print("Error closing order : ",GetLastError());
}
else
{
if(OrderClose(ticket, MAX_LOTS, Bid, 3))
nextTP+=Target_Increment;
else
Print("Error closing order : ",GetLastError());
}
}
}
}
Hai,
Is there anyone in this great forum, could modified this EA without any stop loss.
Thanks
//---- input parameters ---------------------------------------------+
extern int INCREMENT=35;
extern double LOTS=0.1;
extern int LEVELS=3;
extern double MAX_LOTS=99;
extern int MAGIC=1803;
extern bool CONTINUE=true;
extern bool MONEY_MANAGEMENT=false;
extern int RISK_RATIO=2;
//+------------------------------------------------------------------+
bool UseProfitTarget=false;
bool UsePartialProfitTarget=false;
int Target_Increment = 50;
int First_Target = 20;
bool UseEntryTime=false;
int EntryTime=0;
//+------------------------------------------------------------------+
bool Enter=true;
int nextTP;
int init()
{
//+------------------------------------------------------------------+
nextTP = First_Target;
//+------------------------------------------------------------------+
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int ticket, cpt, profit, total=0, BuyGoalProfit, SellGoalProfit, PipsLot;
double ProfitTarget=INCREMENT*2, BuyGoal=0, SellGoal=0, spread=(Ask-Bid)/Point, InitialPrice=0;
//----
if(INCREMENT<MarketInfo(Symbol(),MODE_STOPLEVEL)+spread) INCREMENT=1+MarketInfo(Symbol(),MODE_STOPLEVEL)+spread;
if(MONEY_MANAGEMENT) LOTS=NormalizeDouble(AccountBalance()*AccountLeverage()/1000000*RISK_RATIO,0)*MarketInfo(Symbol(),MODE_MINLOT);
if(LOTS<MarketInfo(Symbol(),MODE_MINLOT))
{
Comment("Not Enough Free Margin to begin");
return(0);
}
for(cpt=1;cpt<LEVELS;cpt++) PipsLot+=cpt*INCREMENT;
for(cpt=0;cpt<OrdersTotal();cpt++)
{
OrderSelect(cpt,SELECT_BY_POS,MODE_TRADES);
if(OrderMagicNumber()==MAGIC && OrderSymbol()==Symbol())
{
total++;
if(!InitialPrice) InitialPrice=StrToDouble(OrderComment());
if(UsePartialProfitTarget && UseProfitTarget && OrderType()<2)
{
double val=getPipValue(OrderOpenPrice(),OrderType());
takeProfit(val,OrderTicket());
}
}
}
if(total<1 && Enter && (!UseEntryTime || (UseEntryTime && Hour()==EntryTime)))
{
if(AccountFreeMargin()<(100*LOTS))
{
Print("Not enough free margin to begin");
return(0);
}
// - Open Check - Start Cycle
InitialPrice=Ask;
SellGoal=InitialPrice-(LEVELS+1)*INCREMENT*Point;
BuyGoal=InitialPrice+(LEVELS+1)*INCREMENT*Point;
for(cpt=1;cpt<=LEVELS;cpt++)
{
OrderSend(Symbol(),OP_BUYSTOP,LOTS,InitialPrice+cpt*INCREMENT*Point,2,SellGoal,BuyGoal,DoubleToStr(InitialPrice,MarketInfo(Symbol(),MODE_DIGITS)),MAGIC,0);
OrderSend(Symbol(),OP_SELLSTOP,LOTS,InitialPrice-cpt*INCREMENT*Point,2,BuyGoal+spread*Point,SellGoal+spread*Point,DoubleToStr(InitialPrice,MarketInfo(Symbol(),MODE_DIGITS)),MAGIC,0);
}
} // initial setup done - all channels are set up
else // We have open Orders
{
BuyGoal=InitialPrice+INCREMENT*(LEVELS+1)*Point;
SellGoal=InitialPrice-INCREMENT*(LEVELS+1)*Point;
total=OrdersHistoryTotal();
for(cpt=0;cpt<total;cpt++)
{
OrderSelect(cpt,SELECT_BY_POS,MODE_HISTORY);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC && StrToDouble(OrderComment())==InitialPrice){EndSession();return(0);}
}
if(UseProfitTarget && CheckProfits(LOTS,OP_SELL,true,InitialPrice)>ProfitTarget) {EndSession();return(0);}
BuyGoalProfit=CheckProfits(LOTS,OP_BUY,false,InitialPrice);
SellGoalProfit=CheckProfits(LOTS,OP_SELL,false,InitialPrice);
if(BuyGoalProfit<ProfitTarget)
// - Incriment Lots Buy
{
for(cpt=LEVELS;cpt>=1 && BuyGoalProfit<ProfitTarget;cpt--)
{
if(Ask<=(InitialPrice+(cpt*INCREMENT-MarketInfo(Symbol(),MODE_STOPLEVEL))*Point))
{
ticket=OrderSend(Symbol(),OP_BUYSTOP,cpt*LOTS,InitialPrice+cpt*INCREMENT*Point,2,SellGoal,BuyGoal,DoubleToStr(InitialPrice,MarketInfo(Symbol(),MODE_DIGITS)),MAGIC,0);
}
if(ticket>0) BuyGoalProfit+=LOTS*(BuyGoal-InitialPrice-cpt*INCREMENT*Point)/Point;
}
}
if(SellGoalProfit<ProfitTarget)
// - Increment Lots Sell
{
for(cpt=LEVELS;cpt>=1 && SellGoalProfit<ProfitTarget;cpt--)
{
if(Bid>=(InitialPrice-(cpt*INCREMENT-MarketInfo(Symbol(),MODE_STOPLEVEL))*Point))
{
ticket=OrderSend(Symbol(),OP_SELLSTOP,cpt*LOTS,InitialPrice-cpt*INCREMENT*Point,2,BuyGoal+spread*Point,SellGoal+spread*Point,DoubleToStr(InitialPrice,MarketInfo(Symbol(),MODE_DIGITS)),MAGIC,0);
}
if(ticket>0) SellGoalProfit+=LOTS*(InitialPrice-cpt*INCREMENT*Point-SellGoal-spread*Point)/Point;
}
}
}
//+------------------------------------------------------------------+
Comment("mGRID EXPERT ADVISOR ver 2.0\n",
"FX Acc Server:",AccountServer(),"\n",
"Date: ",Month(),"-",Day(),"-",Year()," Server Time: ",Hour(),":",Minute(),":",Seconds(),"\n",
"Minimum Lot Sizing: ",MarketInfo(Symbol(),MODE_MINLOT),"\n",
"Account Balance: $",AccountBalance(),"\n",
"Symbol: ", Symbol(),"\n",
"Price: ",NormalizeDouble(Bid,4),"\n",
"Pip Spread: ",MarketInfo("EURUSD",MODE_SPREAD),"\n",
"Increment=" + INCREMENT,"\n",
"Lots: ",LOTS,"\n",
"Levels: " + LEVELS,"\n");
return(0);
}
//+------------------------------------------------------------------+
int CheckProfits(double LOTS, int Goal, bool Current, double InitialPrice)
{
int profit=0, cpt;
if(Current)//return current profit
{
for(cpt=0;cpt<OrdersTotal();cpt++)
{
OrderSelect(cpt, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol() && StrToDouble(OrderComment())==InitialPrice)
{
if(OrderType()==OP_BUY) profit+=(Bid-OrderOpenPrice())/Point*OrderLots()/LOTS;
if(OrderType()==OP_SELL) profit+=(OrderOpenPrice()-Ask)/Point*OrderLots()/LOTS;
}
}
return(profit);
}
else
{
if(Goal==OP_BUY)
{
for(cpt=0;cpt<OrdersTotal();cpt++)
{
OrderSelect(cpt, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol() && StrToDouble(OrderComment())==InitialPrice)
{
if(OrderType()==OP_BUY) profit+=(OrderTakeProfit()-OrderOpenPrice())/Point*OrderLots()/LOTS;
if(OrderType()==OP_SELL) profit-=(OrderStopLoss()-OrderOpenPrice())/Point*OrderLots()/LOTS;
if(OrderType()==OP_BUYSTOP) profit+=(OrderTakeProfit()-OrderOpenPrice())/Point*OrderLots()/LOTS;
}
}
return(profit);
}
else
{
for(cpt=0;cpt<OrdersTotal();cpt++)
{
OrderSelect(cpt, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol() && StrToDouble(OrderComment())==InitialPrice)
{
if(OrderType()==OP_BUY) profit-=(OrderOpenPrice()-OrderStopLoss())/Point*OrderLots()/LOTS;
if(OrderType()==OP_SELL) profit+=(OrderOpenPrice()-OrderTakeProfit())/Point*OrderLots()/LOTS;
if(OrderType()==OP_SELLSTOP) profit+=(OrderOpenPrice()-OrderTakeProfit())/Point*OrderLots()/LOTS;
}
}
return(profit);
}
}
}
bool EndSession()
{
int cpt, total=OrdersTotal();
for(cpt=0;cpt<total;cpt++)
{
Sleep(3000);
OrderSelect(cpt,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderType()>1) OrderDelete(OrderTicket());
else if(OrderSymbol()==Symbol() && OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),Bid,3);
else if(OrderSymbol()==Symbol() && OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),Ask,3);
}
if(!CONTINUE) Enter=false;
return(true);
}
double getPipValue(double ord,int dir)
{
double val;
RefreshRates();
if(dir == 1) val=(NormalizeDouble(ord,Digits) - NormalizeDouble(Ask,Digits));
else val=(NormalizeDouble(Bid,Digits) - NormalizeDouble(ord,Digits));
val = val/Point;
return(val);
}
//========== FUNCTION takeProfit
void takeProfit(int current_pips, int ticket)
{
if(OrderSelect(ticket, SELECT_BY_TICKET))
{
if(current_pips >= nextTP && current_pips < (nextTP + Target_Increment))
{
if(OrderType()==1)
{
if(OrderClose(ticket, MAX_LOTS, Ask, 3))
nextTP+=Target_Increment;
else
Print("Error closing order : ",GetLastError());
}
else
{
if(OrderClose(ticket, MAX_LOTS, Bid, 3))
nextTP+=Target_Increment;
else
Print("Error closing order : ",GetLastError());
}
}
}
}Hi
here you go
jdun,
The code of SL & TP has already written in this EA:
Look at these lines:
PipsForEntry= 13;
TrailingStop = 40;
TakeProfit = 45;
InitialStopLoss=33;
} else if (Symbol()=="EURUSD") {
PipsForEntry= 13;
TrailingStop = 30;
TakeProfit = 45;
InitialStopLoss=23;
} else if (Symbol()=="USDCHF") {
PipsForEntry= 13;
TrailingStop = 30;
TakeProfit = 45;
InitialStopLoss=15;
} else {
PipsForEntry= 13;
TrailingStop = 30;
TakeProfit = 45;
InitialStopLoss=30;
} [/PHP]
If you want to make SL & TP external variables which you can set, you have to comment the above lines of code and uncomment these lines:
[PHP]/*
extern int PipsForEntry= 5;
extern double TrailingStop = 40;
extern double TakeProfit = 120;
extern double InitialStopLoss=50;
*/max trades per signals
Does anybody know what i would use to limit the number of trades per signal ( i would like 1 trade per signal but am getting like 8 and the last one always is a loser)
Help
Hai,
There is still have a stop loss
Hi here you go
EA w/ multiple CUSTOM times ?
I realize an EA can be made w/ multiple time frames, BUT can one be written w/ custom times ? I have an EA w/ MTF but I need custom times not default times so they don't "line up" that often.
regards