//--- input parameters input int lot_multiplier=3,base_lot=1,martingale_max=4; input int cycle_fails=1,magic_number=123,slippage=2;
//declarations for EMA cross double CrossUp[],CrossDown[],smile_yes[],smile_no[],smile_nyes[],lot_size,Risk; extern int FasterEMA = 1; extern int SlowerEMA = 2; extern bool SoundON=true; long alertTag; datetime et=Time[0]+Period();
//initialisations(cycle fail and loos count) made here will not b recognised by the EA once run once int callTICKET,putTICKET,cycle_fail=0,loss_count=0;
//+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+
//+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { if(cycle_fail==cycle_fails)return; switch(UninitializeReason()) { case REASON_CHARTCLOSE: case REASON_REMOVE: break; // clean up and free all expert's resources. case REASON_RECOMPILE: case REASON_CHARTCHANGE: case REASON_PARAMETERS: case REASON_ACCOUNT: break; // prepare to restart } //... } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //the EA will run as long as a cycle failures incurred ahs not been reached(exceeded) //if exceeded the EA will automatical return void if(cycle_fail<cycle_fails) { //Risk amount calculation Risk=base_lot+base_lot*lot_multiplier+base_lot*MathPow(lot_multiplier,2)+base_lot*MathPow(lot_multiplier,3); //comments to be placed on the chart double free=AccountBalance(); Comment("BOMEGA RUNNING LIVE","\n","ACCOUNT BALANCE IS : ",DoubleToStr(free,2),"\n","RISK AMOUNT IS : ",DoubleToStr(Risk,2),"\n","ACCOUNT PROFIT IS : ",AccountProfit());
//ema code int limit,i,counter; double fasterEMAnow,slowerEMAnow,fasterEMAprevious,slowerEMAprevious,fasterEMAafter,slowerEMAafter; double Range,AvgRange; int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted if(counted_bars>0) counted_bars--;
//martingale loop code _precursor code_ to order entry
//code runs so long as failed cycles is less than cycle fails for(int Count=OrdersHistoryTotal()-1;; Count--) { int select=OrderSelect(Count,SELECT_BY_POS,MODE_HISTORY); if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic_number) { if(OrderProfit() < 0) loss_count++; //loss count remains zero or otherwise else if (OrderProfit()==0)loss_count=loss_count; else loss_count=0; break; } //lot size calculation and risk control if(cycle_fail<cycle_fails) { lot_size=base_lot*MathPow(lot_multiplier,loss_count);
//calculation of failed cycles if(loss_count>martingale_max)loss_count=0; cycle_fail++; } //stop investing ie after checking the cycle fail value__ set lot_size to zero else if(cycle_fail==cycle_fails) lot_size=0; }
//signalling for uptrend commencing and order entry if((fasterEMAnow>slowerEMAnow) && (fasterEMAprevious<slowerEMAprevious) && (fasterEMAafter>slowerEMAafter)) { CrossUp[i-1]=Low[i]-Range*0.3; //open a buy order(binary order) callTICKET=OrderSend(Symbol(),OP_BUY,lot_size,Open[0],slippage,0,0,"BO exp:300",magic_number,0,clrRed); //trade status if (Open[i-1]<Close[i-1])smile_yes[i-1]=Low[i]-Range*0.8; if (Open[i-1]>Close[i-1])smile_no[i-1]=Low[i]-Range*0.8; if(Open[i-1]==Close[i-1])smile_nyes[i-1]=Low[i]-Range*0.8; }
//signalling for downtrend commencing and order entry else if((fasterEMAnow<slowerEMAnow) && (fasterEMAprevious>slowerEMAprevious) && (fasterEMAafter<slowerEMAafter)) { CrossDown[i-1]=High[i]+Range*0.3; //open a sell order(binary order) putTICKET=OrderSend(Symbol(),OP_SELL,lot_size,Open[0],slippage,0,0,"BO exp:300",magic_number,0,clrRed); //trade status____ if (Open[i-1]>Close[i-1])smile_yes[i-1]=High[i]+Range*0.8; if (Open[i-1]<Close[i-1])smile_no[i-1]=High[i]+Range*0.8; if(Open[i-1]==Close[i-1])smile_nyes[i-1]=High[i]+Range*0.8; }
//alerts trigger if(SoundON==true && i==1 && CrossUp[i]>CrossDown[i] && alertTag!=Time[0]) { Alert("B_OMEGA Trend going Down on ",Symbol()," ",Period()); alertTag=Time[0]; }
if(SoundON==true && i==1 && CrossUp[i]<CrossDown[i] && alertTag!=Time[0]) { Alert("B_OMEGA Trend going Up on ",Symbol()," ",Period()); alertTag=Time[0]; }
Please edit your post.
For large amounts of code, attach it.
"Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
SetIndexBuffer(0,CrossUp);
SetIndexStyle(1,DRAW_ARROW,EMPTY,1,Red);
int counted_bars=IndicatorCounted();
Those can only be used with indicators. Indicators can not sleep,
We aren't going to fix it for you. learntocode it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.
input int lot_multiplier=3,base_lot=1,martingale_max=4;
input int cycle_fails=1,magic_number=123,slippage=2;
//declarations for EMA cross
double CrossUp[],CrossDown[],smile_yes[],smile_no[],smile_nyes[],lot_size,Risk;
extern int FasterEMA = 1;
extern int SlowerEMA = 2;
extern bool SoundON=true;
long alertTag;
datetime et=Time[0]+Period();
//initialisations(cycle fail and loos count) made here will not b recognised by the EA once run once
int callTICKET,putTICKET,cycle_fail=0,loss_count=0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---- indicators
SetIndexStyle(0,DRAW_ARROW,EMPTY,1,Blue);
SetIndexArrow(0,233);
SetIndexBuffer(0,CrossUp);
SetIndexStyle(1,DRAW_ARROW,EMPTY,1,Red);
SetIndexArrow(1,234);
SetIndexBuffer(1,CrossDown);
//trade status
SetIndexStyle(2,DRAW_ARROW,EMPTY,2,Blue);
SetIndexArrow(2,74);
SetIndexBuffer(2,smile_yes);
SetIndexStyle(3,DRAW_ARROW,EMPTY,2,Red);
SetIndexArrow(3,75);
SetIndexBuffer(3,smile_no);
SetIndexStyle(4,DRAW_ARROW,EMPTY,3,MediumBlue);
SetIndexArrow(4,73);
SetIndexBuffer(4,smile_nyes);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
if(cycle_fail==cycle_fails)return;
switch(UninitializeReason())
{
case REASON_CHARTCLOSE:
case REASON_REMOVE: break; // clean up and free all expert's resources.
case REASON_RECOMPILE:
case REASON_CHARTCHANGE:
case REASON_PARAMETERS:
case REASON_ACCOUNT: break; // prepare to restart
}
//...
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//the EA will run as long as a cycle failures incurred ahs not been reached(exceeded)
//if exceeded the EA will automatical return void
if(cycle_fail<cycle_fails)
{
//Risk amount calculation
Risk=base_lot+base_lot*lot_multiplier+base_lot*MathPow(lot_multiplier,2)+base_lot*MathPow(lot_multiplier,3);
//comments to be placed on the chart
double free=AccountBalance();
Comment("BOMEGA RUNNING LIVE","\n","ACCOUNT BALANCE IS : ",DoubleToStr(free,2),"\n","RISK AMOUNT IS : ",DoubleToStr(Risk,2),"\n","ACCOUNT PROFIT IS : ",AccountProfit());
//ema code
int limit,i,counter;
double fasterEMAnow,slowerEMAnow,fasterEMAprevious,slowerEMAprevious,fasterEMAafter,slowerEMAafter;
double Range,AvgRange;
int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(i=0; i<=limit; i++)
{
counter=i;
Range=0;
AvgRange=0;
for(counter=i;counter<=i+9;counter++)
{
AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
}
Range=AvgRange/10;
fasterEMAnow=iMA(NULL,0,FasterEMA,0,MODE_EMA,PRICE_CLOSE,i);
fasterEMAprevious=iMA(NULL,0,FasterEMA,0,MODE_EMA,PRICE_CLOSE,i+1);
fasterEMAafter=iMA(NULL,0,FasterEMA,0,MODE_EMA,PRICE_CLOSE,i-1);
slowerEMAnow=iMA(NULL,0,SlowerEMA,0,MODE_EMA,PRICE_CLOSE,i);
slowerEMAprevious=iMA(NULL,0,SlowerEMA,0,MODE_EMA,PRICE_CLOSE,i+1);
slowerEMAafter=iMA(NULL,0,SlowerEMA,0,MODE_EMA,PRICE_CLOSE,i-1);
//martingale loop code _precursor code_ to order entry
//code runs so long as failed cycles is less than cycle fails
for(int Count=OrdersHistoryTotal()-1;; Count--)
{
int select=OrderSelect(Count,SELECT_BY_POS,MODE_HISTORY);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic_number)
{
if(OrderProfit() < 0) loss_count++;
//loss count remains zero or otherwise
else if (OrderProfit()==0)loss_count=loss_count;
else loss_count=0;
break;
}
//lot size calculation and risk control
if(cycle_fail<cycle_fails)
{
lot_size=base_lot*MathPow(lot_multiplier,loss_count);
//calculation of failed cycles
if(loss_count>martingale_max)loss_count=0; cycle_fail++;
}
//stop investing ie after checking the cycle fail value__ set lot_size to zero
else if(cycle_fail==cycle_fails) lot_size=0;
}
//signalling for uptrend commencing and order entry
if((fasterEMAnow>slowerEMAnow) && (fasterEMAprevious<slowerEMAprevious) && (fasterEMAafter>slowerEMAafter))
{
CrossUp[i-1]=Low[i]-Range*0.3;
//open a buy order(binary order)
callTICKET=OrderSend(Symbol(),OP_BUY,lot_size,Open[0],slippage,0,0,"BO exp:300",magic_number,0,clrRed);
//trade status
if (Open[i-1]<Close[i-1])smile_yes[i-1]=Low[i]-Range*0.8;
if (Open[i-1]>Close[i-1])smile_no[i-1]=Low[i]-Range*0.8;
if(Open[i-1]==Close[i-1])smile_nyes[i-1]=Low[i]-Range*0.8;
}
//signalling for downtrend commencing and order entry
else if((fasterEMAnow<slowerEMAnow) && (fasterEMAprevious>slowerEMAprevious) && (fasterEMAafter<slowerEMAafter))
{
CrossDown[i-1]=High[i]+Range*0.3;
//open a sell order(binary order)
putTICKET=OrderSend(Symbol(),OP_SELL,lot_size,Open[0],slippage,0,0,"BO exp:300",magic_number,0,clrRed);
//trade status____
if (Open[i-1]>Close[i-1])smile_yes[i-1]=High[i]+Range*0.8;
if (Open[i-1]<Close[i-1])smile_no[i-1]=High[i]+Range*0.8;
if(Open[i-1]==Close[i-1])smile_nyes[i-1]=High[i]+Range*0.8;
}
//alerts trigger
if(SoundON==true && i==1 && CrossUp[i]>CrossDown[i] && alertTag!=Time[0])
{
Alert("B_OMEGA Trend going Down on ",Symbol()," ",Period());
alertTag=Time[0];
}
if(SoundON==true && i==1 && CrossUp[i]<CrossDown[i] && alertTag!=Time[0])
{
Alert("B_OMEGA Trend going Up on ",Symbol()," ",Period());
alertTag=Time[0];
}