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
...
For run-time spread(s) use this :
I want to show spread real time code inside EA. Any please give me some advice.
Thank you malden. But I know that PHP code for web server . I do not know to code in side EA. Or It's stand for others.
Please tell me more specific. Sorry I just new in MQL4 programing.
And I an not sure how and which part of program was executed when new price coming in.
The whole of program or in side init() or inside start().
I want to get tick information and show like I ask this thread .
Premeus
That is metatrader MQl 4 code that gets the spread for current symbol. Just copy it to your code and you will have the spread information retrieved that way
That line of code should be in start() in order to check the spread on each and every tick (since it can change on each tick). Once you called the MarketInfo() function and the currentSpread variable gets assigned the value, use the currentSpread to whatever tests or any further processing you need
Thank you malden. But I know that PHP code for web server . I do not know to code in side EA. Or It's stand for others.
Please tell me more specific. Sorry I just new in MQL4 programing.
And I an not sure how and which part of program was executed when new price coming in.
The whole of program or in side init() or inside start().
I want to get tick information and show like I ask this thread .MartingailExpert_v1.0_Stochastic, how?
Hi!
Can someone tell me, why I can t insert Stoploss in Order send ticket?
When I insert it, EA won t work!
Thanks!
//| aaa.mq4 |
//| Copyright Š 2007, MetaQuotes Software Corp. |
//| TeamWox Groupware / MetaQuotes Software Corp. |
//+------------------------------------------------------------------+
#property copyright "Copyright Š 2007, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
extern double step=25;
extern int StepMode=0;
// Ĺńëč StepMode = 0, ňî řŕă ěĺćäó îđäĺđŕěč ôčęńčđîâŕííűé č đŕâĺí step
// Ĺńëč StepMode = 1, ňî řŕă ďîńňĺďĺííî óâĺëč÷čâŕĺňń˙
extern double proffactor=10;
extern double mult=1.5;
extern double lotsbuy=0.01;
extern double lotssell=0.01;
extern double per_K=200;
extern double per_D=20;
extern double slow=20;
extern double zoneBUY=20;
extern double zoneSELL=80;
extern double Magicbuy=555;
extern double Magicsell=556;
double openpricebuy,openpricesell,lotsbuy2,lotssell2,lastlotbuy,lastlotsell,tpb,tps,cnt,smbuy,smsell,lotstep,
ticketbuy,ticketsell,maxLot,free,balance,lotsell,lotbuy,dig,sig_buy,sig_sell,ask,bid;
int OrdersTotalMagicbuy(int Magicbuy)
{
int j=0;
int r;
for (r=0;r<OrdersTotal();r++)
{
if(OrderSelect(r,SELECT_BY_POS,MODE_TRADES))
{
if (OrderMagicNumber()==Magicbuy) j++;
}
}
return(j);
}
int OrdersTotalMagicsell(int Magicsell)
{
int d=0;
int n;
for (n=0;n<OrdersTotal();n++)
{
if(OrderSelect(n,SELECT_BY_POS,MODE_TRADES))
{
if (OrderMagicNumber()==Magicsell) d++;
}
}
return(d);
}
int orderclosebuy(int ticketbuy)
{
string symbol = Symbol();
int cnt;
for(cnt = OrdersTotal(); cnt >= 0; cnt--)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol() == symbol && OrderMagicNumber()==Magicbuy)
{
ticketbuy=OrderTicket();OrderSelect(ticketbuy, SELECT_BY_TICKET, MODE_TRADES);lotsbuy2=OrderLots() ;
double bid = MarketInfo(symbol,MODE_BID);
RefreshRates();
OrderClose(ticketbuy,lotsbuy2,bid,3,Magenta);
}
}
lotsbuy2=lotsbuy;return(0);
}
int orderclosesell(int ticketsell)
{
string symbol = Symbol();
int cnt;
for(cnt = OrdersTotal(); cnt >= 0; cnt--)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol() == symbol && OrderMagicNumber()==Magicsell)
{
ticketsell=OrderTicket();OrderSelect(ticketsell, SELECT_BY_TICKET, MODE_TRADES);lotssell2=OrderLots() ;
double ask = MarketInfo(symbol,MODE_ASK);
RefreshRates();
OrderClose(ticketsell,lotssell2,ask,3, Lime);
}
}
lotssell2=lotssell;return(0);
}
int start()
{
//----
double profitbuy=0;double profitsell=0;
string symbol = OrderSymbol();
double spread = MarketInfo(symbol,MODE_SPREAD);
double minLot = MarketInfo(symbol,MODE_MINLOT);
if (minLot==0.01){dig=2;maxLot=MarketInfo(symbol,MODE_MAXLOT);}
if (minLot==0.1){dig=1;maxLot=((AccountBalance()/2)/1000);}
if(OrdersTotalMagicbuy(Magicbuy)>0)
{
double smbuy;
for (cnt=0;cnt<OrdersTotal();cnt++)
{
OrderSelect(cnt,SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol() && OrderMagicNumber () == Magicbuy)
{
ticketbuy = OrderTicket();OrderSelect(ticketbuy,SELECT_BY_TICKET, MODE_TRADES);
smbuy = smbuy+OrderLots();openpricebuy = OrderOpenPrice();lastlotbuy = OrderLots();
}
}
{
if (smbuy+(NormalizeDouble((lastlotbuy*mult),dig))<maxLot)
{
if(StepMode==0)
{
if(Ask<=openpricebuy-step*Point)
{
lotsbuy2=lastlotbuy*mult;
RefreshRates();ticketbuy=OrderSend(Symbol(),OP_BUY,NormalizeDouble(lotsbuy2,dig),Ask,3,0,0,"MartingailExpert",Magicbuy,0,Blue);
}
}
if(StepMode==1)
{
if(Ask<=openpricebuy-(step+OrdersTotalMagicbuy(Magicbuy)+OrdersTotalMagicbuy(Magicbuy)-2)*Point)
{
lotsbuy2=lastlotbuy*mult;
RefreshRates();ticketbuy=OrderSend(Symbol(),OP_BUY,NormalizeDouble(lotsbuy2,dig),Ask,3,0,0,"MartingailExpert",Magicbuy,0,Blue);
}
}
}
}
}
if(OrdersTotalMagicsell(Magicsell)>0)
{
double smsell;
for (cnt=0;cnt<OrdersTotal();cnt++)
{
OrderSelect(cnt,SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol() && OrderMagicNumber () == Magicsell)
{
ticketsell = OrderTicket();OrderSelect(ticketsell,SELECT_BY_TICKET, MODE_TRADES);
smsell = smsell + OrderLots();openpricesell = OrderOpenPrice();lastlotsell = OrderLots();
}
}
{
if (smsell+(NormalizeDouble((lastlotsell*mult),dig))<maxLot)
{
if(StepMode==0)
{
if(Bid>=openpricesell+step*Point)
{
lotssell2=lastlotsell*mult;
RefreshRates();ticketsell=OrderSend(Symbol(),OP_SELL,NormalizeDouble(lotssell2,dig),Bid,3,0,0,"MartingailExpert",Magicsell,0,Red);
}
}
if(StepMode==1)
{
if(Bid>=openpricesell+(step+OrdersTotalMagicsell(Magicsell)+OrdersTotalMagicsell(Magicsell)-2)*Point)
{
lotssell2=lastlotsell*mult;
RefreshRates();ticketsell=OrderSend(Symbol(),OP_SELL,NormalizeDouble(lotssell2,dig),Bid,3,0,0,"MartingailExpert",Magicsell,0,Red);
}
}
}
}
}
//xm7 modification to change the way signal is generated. Old code is at end
double Stoch_0 = iStochastic(NULL,0,per_K,per_D,slow,MODE_LWMA,1,0,0);
double Stoch_1 = iStochastic(NULL,0,per_K,per_D,slow,MODE_LWMA,1,0,1);
if(OrdersTotalMagicbuy(Magicbuy)<1)
{
if(Stoch_0 > zoneBUY && Stoch_1 <= zoneBUY)
ticketbuy = OrderSend(Symbol(),OP_BUY,lotsbuy,Ask,3,0,0,"MartingailExpert",Magicbuy,0,Blue);
}
if(OrdersTotalMagicsell(Magicsell)<1)
{
if(Stoch_0 = zoneSELL)
ticketsell = OrderSend(Symbol(),OP_SELL,lotssell,Bid,3,0,0,"MartingailExpert",Magicsell,0,Red);
}
for (cnt=0;cnt<OrdersTotal();cnt++)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderSymbol()==Symbol() && OrderMagicNumber () == Magicbuy)
{
ticketbuy = OrderTicket();OrderSelect(ticketbuy,SELECT_BY_TICKET, MODE_TRADES);profitbuy = profitbuy+OrderProfit() ;
openpricebuy = OrderOpenPrice();
}
}
tpb = (OrdersTotalMagicbuy(Magicbuy)*proffactor*Point)+openpricebuy;
double bid = MarketInfo(Symbol(),MODE_BID);
if (profitbuy>0)
{
if (Bid>=tpb) orderclosebuy(ticketbuy);
}
for (cnt=0;cnt<OrdersTotal();cnt++)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magicsell)
{
ticketsell = OrderTicket();OrderSelect(ticketsell,SELECT_BY_TICKET, MODE_TRADES);profitsell = profitsell+OrderProfit();
openpricesell = OrderOpenPrice();
}
}
tps = openpricesell-(OrdersTotalMagicsell(Magicsell)*proffactor*Point);
double ask = MarketInfo(Symbol(),MODE_ASK);
if (profitsell>0)
{
if (Ask<=tps)orderclosesell(ticketsell);
}
free = AccountFreeMargin();balance = AccountBalance();
for (cnt=0;cnt< OrdersTotal();cnt++)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderSymbol()==Symbol() && OrderMagicNumber () == Magicbuy) ticketbuy = OrderTicket();
if (OrderSymbol()==Symbol() && OrderMagicNumber () == Magicsell) ticketsell = OrderTicket();
}
if (OrdersTotalMagicbuy(Magicbuy)==0)
{
profitbuy=0;ticketbuy=0;tpb=0;
}
if (OrdersTotalMagicsell(Magicsell)==0)
{
profitsell=0;ticketsell=0;tps=0;
}
Comment("FreeMargin = ",NormalizeDouble(free,0)," Balance = ",NormalizeDouble(balance,0)," maxLot = ",NormalizeDouble(maxLot,dig),"\n",
"Totalbuy = ",OrdersTotalMagicbuy(Magicbuy)," Lot = ",smbuy," Totalsell = ",OrdersTotalMagicsell(Magicsell)," Lot = ",smsell,"\n",
"---------------------------------------------------------------","\n","Profitbuy = ",profitbuy,"\n",
"Profitsell = ",profitsell);
//----
for(int ii=0; ii<2; ii+=2)
{
ObjectDelete("rect"+ii);
ObjectCreate("rect"+ii,OBJ_HLINE, 0, 0,tps);
ObjectSet("rect"+ii, OBJPROP_COLOR, Red);
ObjectSet("rect"+ii, OBJPROP_WIDTH, 1);
ObjectSet("rect"+ii, OBJPROP_RAY, False);
}
for(int rr=0; rr<2; rr+=2)
{
ObjectDelete("rect1"+rr);
ObjectCreate("rect1"+rr,OBJ_HLINE, 0, 0,tpb);
ObjectSet("rect1"+rr, OBJPROP_COLOR, Blue);
ObjectSet("rect1"+rr, OBJPROP_WIDTH, 1);
ObjectSet("rect1"+rr, OBJPROP_RAY, False);
}
return(0);
}...
It can be a couple of reasons, but the most common are :
Hi!
Can someone tell me, why I can t insert Stoploss in Order send ticket?
When I insert it, EA won t work!
Thanks!Hi all, I would like to check on how do I get the latest current price on the chart? I know its noob, but I cant seem to find the ans. Please help. Thanks.
Regards
Terrance
...
Depends which one :
Hi all, I would like to check on how do I get the latest current price on the chart? I know its noob, but I cant seem to find the ans. Please help. Thanks.
Regards
TerranceHi Mladen, What I am trying to do is a check. Example, if the current price is above say SMA 100, I will zoom down to a lower time frame and will only look at buy signal. But if i use Bid or Ask, the system cannot decide if I am currently looking at long or short since Bid I should be looking for long and vice versa for Ask (correct me if I am wrong here).
The concept I had in mind is some what similar to the 3 duck trading system on the checking portion. Please advise me here. Thanks.
Regards
Terrance
Depends which one :
...
Terrance
Use Close[0] in that case. Almost every EA is using close for that purpose, so I think that it will work for you too
Hi Mladen, What I am trying to do is a check. Example, if the current price is above say SMA 100, I will zoom down to a lower time frame and will only look at buy signal. But if i use Bid or Ask, the system cannot decide if I am currently looking at long or short since Bid I should be looking for long and vice versa for Ask (correct me if I am wrong here).
The concept I had in mind is some what similar to the 3 duck trading system on the checking portion. Please advise me here. Thanks.
Regards
TerranceEA not running between price moving
I noticed my EA not running between price moving in M1 time frame. I know that EA will be executed every tick coming in.
But I saw it's was executed every it's start new bar.
Am I misunderstanding ?
Are there the way the force ea activate every tick coming in?
I try to control my profit and loss by use profits and loss not in pips. When spike happen EA not close order when reach to setting profits or loss until new bar occur.
Anyone help me to solve this problem.
I am new for EA coding.
Thank you in advance.