Cammixxo
02-09-2009 17:06, 05:06 PM
Greetings!
I figure I am following the usual story here. New to MQL4, a few programming history (BASIC and HTML), blah,blah,blah, now I am trying my hands at writing my own EA.
It's nothing special. I am working in an EMA breakout EA. I believed that I would keep it simple, as it's one of my first. So that the EA works based on a pub shutting over the line and opening below the 20 EMA. The bar it opens an order a 3 pips over the bar. As it's a EA the order is closed upon hitting on the TP or SL point, it has no other programming for final an order.
Here is the problem. The version I have unlocks an order . Nice once you have a profitable trade, sucks if you don't. In version 2 I found that any transactions does not open and tried adding in a counter code from another EA.
Here is the version 1 suggestion (sorry I don't understand how to set it in a neat little box):
int start()
//--
int cnt, complete, ticket;
double emaT = iMA(NULL,0,20,0,MODE_EMA, PRICE_CLOSE,0);
double MacdCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_ MAIN,0);
complete=OrdersTotal();
if(totallt;1)
bool buy = false;
bool market = false;
if((Ask==High[1] gt; 3*Stage) (Open[1] lt; emaT) (Close[1] gt; emaT) (MacdCurrent gt; 0)) buy = true;
if((Low[1]==Bid gt; 3*Stage) (emaT gt; Close[1]) (Open[1] gt; emaT) (MacdCurrent lt; 0)) market = true;
if(buy)
ticket=OrderSend(Symbol(),OP_BUY,Lots, Ask,0,Ask-StopLoss*Stage,Ask TakeProfit*Point, Momo Trade,magicnumber,0, Green);
if(ticketgt;0)
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES ))
return(0);
if(market)
ticket=OrderSend(Symbol(),OP_SELL,Lots, Bid,0,Bid StopLoss*Point, Bid-TakeProfit*Point, Momo Trade,magicnumber,0, Red);
if(ticketgt;0)
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES ))
return(0);
return(0);
//--
Version 2 is exactly the same, but using this code added to get a counter:
orders=OrdersTotal();
for(cnt=0;cntlt;OrdersTotal();cnt )
{
if(OrderSelect(cnt,SELECT_BY_POS))
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY)
Additionally, although I have everybody's focus is my code right for putting an order based on the preceding high/low with the (Ask==High[1] gt; 3*Stage) code?
With Due!
I figure I am following the usual story here. New to MQL4, a few programming history (BASIC and HTML), blah,blah,blah, now I am trying my hands at writing my own EA.
It's nothing special. I am working in an EMA breakout EA. I believed that I would keep it simple, as it's one of my first. So that the EA works based on a pub shutting over the line and opening below the 20 EMA. The bar it opens an order a 3 pips over the bar. As it's a EA the order is closed upon hitting on the TP or SL point, it has no other programming for final an order.
Here is the problem. The version I have unlocks an order . Nice once you have a profitable trade, sucks if you don't. In version 2 I found that any transactions does not open and tried adding in a counter code from another EA.
Here is the version 1 suggestion (sorry I don't understand how to set it in a neat little box):
int start()
//--
int cnt, complete, ticket;
double emaT = iMA(NULL,0,20,0,MODE_EMA, PRICE_CLOSE,0);
double MacdCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_ MAIN,0);
complete=OrdersTotal();
if(totallt;1)
bool buy = false;
bool market = false;
if((Ask==High[1] gt; 3*Stage) (Open[1] lt; emaT) (Close[1] gt; emaT) (MacdCurrent gt; 0)) buy = true;
if((Low[1]==Bid gt; 3*Stage) (emaT gt; Close[1]) (Open[1] gt; emaT) (MacdCurrent lt; 0)) market = true;
if(buy)
ticket=OrderSend(Symbol(),OP_BUY,Lots, Ask,0,Ask-StopLoss*Stage,Ask TakeProfit*Point, Momo Trade,magicnumber,0, Green);
if(ticketgt;0)
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES ))
return(0);
if(market)
ticket=OrderSend(Symbol(),OP_SELL,Lots, Bid,0,Bid StopLoss*Point, Bid-TakeProfit*Point, Momo Trade,magicnumber,0, Red);
if(ticketgt;0)
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES ))
return(0);
return(0);
//--
Version 2 is exactly the same, but using this code added to get a counter:
orders=OrdersTotal();
for(cnt=0;cntlt;OrdersTotal();cnt )
{
if(OrderSelect(cnt,SELECT_BY_POS))
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY)
Additionally, although I have everybody's focus is my code right for putting an order based on the preceding high/low with the (Ask==High[1] gt; 3*Stage) code?
With Due!