Jump to content

Edit an EA


panamamike

Recommended Posts

----------------------------+

 

//| TheMadHATter.mq4 |

 

//| Copyright © 2009, MadHatter |

 

//| [email protected] |

 

//+------------------------------------------------------------------+

 

#property copyright "Copyright © 2009, TheMadHATter"

 

#property link "[email protected]"

 

 

 

#include <stderror.mqh>

 

#include <stdlib.mqh>

 

 

 

//User Configurable Variables

 

extern double dLots=1.0;

 

extern double dStopLoss=50;

 

extern double dTakeProfit=50;

 

extern int iSlippage=3;

 

extern int iMaxTrades=1;

 

extern int iMagicNumber=1000;

 

extern bool FractionalPips = true;

 

extern int iStartTime = 7;

 

extern int iEndTime = 23;

 

//variable for calculating stop/loss order modification

 

int pip;

 

 

 

//BB indicator configurable parameters

 

//extern int BB_Length=20; // Heiken Ashi Period

 

//extern int BB_Deviation=2; // Deviation

 

//extern double BB_MoneyRisk=1.00; // Offset Factor

 

//extern int BB_Signal=2; // Display signals mode: 1-Signals & Stops; 0-only Stops; 2-only Signals;

 

//extern int BB_Line=1; // Display line mode: 0-no,1-yes

 

//extern int BB_Nbars=1000;

 

 

 

//Heiken Ashi indicator configurable parameters

 

extern int MaMetod = 2;

 

extern int MaPeriod = 6;

 

extern int MaMetod2 = 3;

 

extern int MaPeriod2 = 2;

 

extern bool POP_UP_Box_Alert = false;

 

extern bool Sound_Alert = false;

 

 

 

//misc processing and tracking variables

 

bool bNewBar;

 

double BB0;

 

double BB1;

 

string strTrend;

 

string strShift;

 

int iTrendShifts;

 

int iAttempts;

 

bool bInit;

 

int currDay;

 

 

 

// Trade Signal Variables

 

int iTradeSignal=0;

 

int iOpenBuySignal=100;

 

int iCloseBuySignal=-200;

 

int iOpenSellSignal=300;

 

int iCloseSellSignal=-400;

 

int iNoSignal=-1;

 

 

 

// Open Trade Information Variables

 

int iLastTradeType;

 

int iTotalTrades;

 

double dTotalTradeLots;

 

double dTotalTradeSwap;

 

int iTotalBuyTrades;

 

int iTotalSellTrades;

 

double dLastTradeOpenPrice;

 

int iLastTradeOpenTime;

 

double dLastTradeStopLoss;

 

double dLastTradeTakeProfit;

 

double dLastTradeType;

 

double dLastTradeTicket;

 

string strLastTradeSymbol;

 

string strLastTradeComment;

 

double dTotalOpenProfit;

 

int iTotalSelectedTrades;

 

 

 

//+------------------------------------------------------------------+

 

//| expert initialization function |

 

//+------------------------------------------------------------------+

 

int init()

 

{

 

//----

 

iLastTradeType=-1;

 

strTrend="neutral";

 

strShift="changed";

 

iTrendShifts=0;

 

bInit=true;

 

bNewBar=false;

 

 

 

if(FractionalPips==true)

 

{

 

pip=10;

 

} else {

 

pip =1;

 

}

 

//----

 

return(0);

 

}

 

//+------------------------------------------------------------------+

 

//| expert deinitialization function |

 

//+------------------------------------------------------------------+

 

int deinit()

 

{

 

//----

 

 

 

//----

 

return(0);

 

}

 

//+------------------------------------------------------------------+

 

//| expert start function |

 

//+------------------------------------------------------------------+

 

int start()

 

{

 

//----

 

 

 

if (bInit==false)

 

{

 

bNewBar=fnNewBar();

 

if (bNewBar==true)

 

{

 

 

 

datetime currTime;

 

int currHour;

 

currTime=TimeCurrent();

 

currHour=TimeHour(currTime);

 

currDay=TimeDayOfWeek(currTime);

 

 

 

if (currDay==5)

 

{

 

Print ("No trades on Friday.");

 

} else {

 

 

 

if (currHour > (iStartTime - 1) && currHour < iEndTime )

 

{

 

 

 

 

 

//BB0=iCustom(NULL,Period(),"bbands-stops",BB_Length,BB_Deviation,BB_MoneyRisk,BB_Signal,BB_Line,BB_Nbars,2,1); //up trend

 

//BB1=iCustom(NULL,Period(),"bbands-stops",BB_Length,BB_Deviation,BB_MoneyRisk,BB_Signal,BB_Line,BB_Nbars,3,1); //down trend

 

 

 

BB0=iCustom(Symbol(),Period(),"Heiken_Ashi_Smoothed_Alert_Bar1",MaMetod,MaPeriod,MaMetod2,MaPeriod2,POP_UP_Box_Alert,Sound_Alert,0,0); //up trend

 

BB1=iCustom(Symbol(),Period(),"Heiken_Ashi_Smoothed_Alert_Bar1",MaMetod,MaPeriod,MaMetod2,MaPeriod2,POP_UP_Box_Alert,Sound_Alert,1,0); //down trend

 

 

 

Print(strTrend + " " + iTrendShifts);

 

 

 

fnGetTrend();

 

fnGetOpenTradeInfo();

 

 

 

if (strShift=="changed" && iTrendShifts > 1)

 

{

 

 

 

if (strTrend=="up")

 

{

 

 

 

if (iLastTradeType==-1)

 

{

 

iTradeSignal = iOpenBuySignal;

 

Print ("Open Buy Signal " + Close[1] + " " + strTrend + " " + BB0 + " " + BB1);

 

fnOrder();

 

}

 

 

 

if (iLastTradeType==OP_SELL)

 

{

 

iTradeSignal = iCloseSellSignal;

 

Print ("Close Sell Signal " + Close[1] + " " + strTrend + " " + BB0 + " " + BB1);

 

fnOrder();

 

 

 

iTradeSignal = iOpenBuySignal;

 

Print ("Open Buy Signal " + Close[1] + " " + strTrend + " " + BB0 + " " + BB1);

 

fnOrder();

 

 

 

}

 

 

 

}//end if trend up

 

 

 

if (strTrend=="down")

 

{

 

 

 

if (iLastTradeType==-1)

 

{

 

iTradeSignal = iOpenSellSignal;

 

Print ("Open Sell Signal " + Close[1] + " " + strTrend + " " + BB0 + " " + BB1);

 

fnOrder();

 

}

 

 

 

 

 

if (iLastTradeType==OP_BUY)

 

{

 

iTradeSignal = iCloseBuySignal;

 

Print ("Close Buy Signal " + Close[1] + " " + strTrend + " " + BB0 + " " + BB1);

 

fnOrder();

 

 

 

iTradeSignal = iOpenSellSignal;

 

Print ("Open Sell Signal " + Close[1] + " " + strTrend + " " + BB0 + " " + BB1);

 

fnOrder();

 

}

 

 

 

}//end if trend down

 

 

 

strShift="unchanged";

 

}//end if trend shifted and eligible for trade

 

 

 

} else {

 

//Print("No trades allowed.");

 

}//end if out of time frame

 

 

 

} // end if day of week is Friday

 

 

 

} //end if new bar

 

 

 

} else {

 

bInit=false;

 

Print ("Initialized and didn't perform any logic.");

 

Print ("Initialization Open1: " + Open[1] + " Open2: " + Open[2] + " Open3: " + Open[3] + " Open4: " + Open[4] + " Open5: " + Open[5] );

 

}//end if initialized is true

 

 

 

//----

 

return(0);

 

}

 

//+------------------------------------------------------------------+

 

 

 

double dOpen1;

 

double dOpen2;

 

double dOpen3;

 

double dOpen4;

 

double dOpen5;

 

 

 

bool fnNewBar()

 

{

 

 

 

if (Open[1]!=dOpen1 || Open[2]!=dOpen2 || Open[3]!=dOpen3 || Open[4]!=dOpen4 || Open[5]!=dOpen5)

 

{

 

 

 

Print ("New Bar Open1: " + Open[1] + "/" + dOpen1 + " Open2: " + Open[2] + "/" + dOpen2 + " Open3: " + Open[3] + "/" + dOpen3 + " Open4: " + Open[4] + "/" + dOpen4 + " Open5: " + Open[5] + "/" + dOpen5 );

 

 

 

dOpen1=Open[1];

 

dOpen2=Open[2];

 

dOpen3=Open[3];

 

dOpen4=Open[4];

 

dOpen5=Open[5];

 

 

 

return(true);

 

 

 

} else {

 

return(false);

 

}

 

 

 

}

Link to comment
Share on other sites

/Get Heike Ashi trend

 

void fnGetTrend()

 

{

 

 

 

if (BB1 > BB0 && (strTrend=="neutral" || strTrend=="down"))

 

{

 

strTrend="up";

 

Print ("Trend shift up BB0 " + BB0 + " BB1 " + BB1);

 

strShift="changed";

 

iTrendShifts++;

 

}

 

 

 

if (BB0 > BB1 && (strTrend=="neutral" || strTrend=="up"))

 

{

 

strTrend="down";

 

Print ("Trend shift down BB1 " + BB1 + " BB0 " + BB0);

 

strShift="changed";

 

iTrendShifts++;

 

}

 

 

 

//return;

 

 

 

}

 

 

 

 

 

void fnGetOpenTradeInfo()

 

{

 

dTotalOpenProfit=0;

 

dTotalTradeLots=0;

 

iTotalBuyTrades=0;

 

iTotalSellTrades=0;

 

dTotalTradeSwap=0;

 

iTotalSelectedTrades=0;

 

 

 

iTotalTrades=OrdersTotal();

 

 

 

if (iTotalTrades==0)

 

{

 

iLastTradeType=-1;

 

}

 

 

 

for(int pos=0;pos<iTotalTrades;pos++)

 

{

 

if(OrderSelect(pos,SELECT_BY_POS)==false)

 

continue;

 

 

 

if( (( OrderSymbol() == Symbol() ) ) && (( OrderMagicNumber() == iMagicNumber ) ) )

 

{

 

iTotalSelectedTrades++;

 

dTotalOpenProfit += OrderProfit();

 

dTotalTradeSwap += OrderSwap();

 

dTotalTradeLots += OrderLots();

 

 

 

if( OrderType() == OP_BUY )

 

{

 

iTotalBuyTrades++;

 

iLastTradeType = OP_BUY;

 

}

 

 

 

if( OrderType() == OP_SELL )

 

{

 

iTotalSellTrades++;

 

iLastTradeType = OP_SELL;

 

}

 

 

 

if ( OrderType() != OP_SELL && OrderType() != OP_BUY)

 

{

 

iLastTradeType = -1;

 

}

 

}

 

}

 

}

 

 

 

 

 

 

 

void fnOrder()

 

{

 

int iOrderOpenStatus;

 

string strErrorMessage;

 

int iErrorNumber;

 

bool bOrderCloseStatus;

 

bool bOrderModifyStatus;

 

 

 

if( (iTradeSignal == iOpenBuySignal) && (iMaxTrades > iTotalSelectedTrades) )

 

{

 

 

 

RefreshRates();

 

double dBuyStopLoss = (Ask-(dStopLoss*(Point*pip)));

 

double dBuyTakeProfit = (Ask+(dTakeProfit*(Point*pip)));

 

Print ("order params: " + Ask);

 

//modified 20090504

 

//iOrderOpenStatus = OrderSend(Symbol(),OP_BUY,dLots,Ask,iSlippage,dBuyStopLoss,dBuyTakeProfit,"BBTrendShift_Buy_"+Symbol()+"_"+Period(),iMagicNumber,0,White);

 

iOrderOpenStatus = OrderSend(Symbol(),OP_BUY,dLots,Ask,0,0,0,"HeikenAshiTrend_Buy_"+Symbol()+"_"+Period(),iMagicNumber,0,White);

 

Print ("Buy/Long Order #: " + iOrderOpenStatus);

 

 

 

if( iOrderOpenStatus < 0 )

 

{

 

iErrorNumber = GetLastError();

 

strErrorMessage = ErrorDescription(iErrorNumber);

 

Alert( "OrderSend Failed: ", strErrorMessage );

 

iAttempts=0;

 

 

 

while (iOrderOpenStatus < 0)

 

{

 

Alert("Retrying buy order... " + iAttempts);

 

RefreshRates();

 

//modified 20090504

 

//iOrderOpenStatus = OrderSend(Symbol(),OP_BUY,dLots,Ask,iSlippage,dBuyStopLoss,dBuyTakeProfit,"BBTrendShift_Buy_"+Symbol()+"_"+Period(),iMagicNumber,0,White);

 

iOrderOpenStatus = OrderSend(Symbol(),OP_BUY,dLots,Ask,0,0,0,"HeikenAshiTrend_Buy_"+Symbol()+"_"+Period(),iMagicNumber,0,White);

 

iAttempts++;

 

Sleep(35000);

 

 

 

if (iAttempts==10)

 

{

 

iOrderOpenStatus=0;

 

Alert("Buy order failed after 10 attempts");

 

}

 

 

 

}

 

 

 

} // end of if iOrderOpenStatus

 

 

 

//modified 20090504

 

 

 

if ( iOrderOpenStatus > 0 )

 

{

 

 

 

if ( OrderSelect(iOrderOpenStatus,SELECT_BY_TICKET)==true )

 

{

 

RefreshRates();

 

dBuyStopLoss = (Ask-(dStopLoss*(Point*pip)));

 

dBuyTakeProfit = (Ask+(dTakeProfit*(Point*pip)));

 

bOrderModifyStatus = OrderModify(OrderTicket(),OrderOpenPrice(),dBuyStopLoss,dBuyTakeProfit, 0, Green);

 

if( bOrderModifyStatus == false )

 

{

 

iErrorNumber = GetLastError();

 

strErrorMessage = ErrorDescription(iErrorNumber);

 

Alert( "Order Modify Failed: ", strErrorMessage );

 

iAttempts=0;

 

 

 

while (bOrderModifyStatus == false)

 

{

 

Alert("Retrying order modify.");

 

RefreshRates();

 

dBuyStopLoss = (Ask-(dStopLoss*(Point*pip)));

 

dBuyTakeProfit = (Ask+(dTakeProfit*(Point*pip)));

 

bOrderModifyStatus = OrderModify(OrderTicket(),OrderOpenPrice(),dBuyStopLoss,dBuyTakeProfit, 0, Green);

 

iAttempts++;

 

Sleep(35000);

 

 

 

if (iAttempts==10)

 

{

 

bOrderModifyStatus=true;

 

Alert("Modify order failed after 10 attempts");

 

}

 

 

 

}

 

return;

 

 

 

} else { // end of if bOrderCloseStatus

 

Print ("Buy order modified.");

 

//iTotalSelectedTrades=0;

 

}

 

}

 

}

 

 

 

//end modified 20090504

 

 

 

return;

 

 

 

} // end of if iOpenBuySignal

 

 

 

if( (iTradeSignal == iOpenSellSignal) && (iMaxTrades > iTotalSelectedTrades) )

 

{

 

 

 

RefreshRates();

 

double dSellStopLoss = Bid+(dStopLoss*(Point*pip));

 

double dSellTakeProfit = Bid-(dTakeProfit*(Point*pip));

 

Print ("order params: " + Bid);

 

//modified 20090504

 

//iOrderOpenStatus = OrderSend(Symbol(),OP_SELL,dLots,Bid,iSlippage,dSellStopLoss,dSellTakeProfit,"BBTrendShift_Sell_"+Symbol()+"_"+Period(),iMagicNumber,0,Black);

 

iOrderOpenStatus = OrderSend(Symbol(),OP_SELL,dLots,Bid,0,0,0,"HeikenAshiTrend_Sell_"+Symbol()+"_"+Period(),iMagicNumber,0,Black);

 

Print ("Sell/Short Order #: " + iOrderOpenStatus);

 

 

 

if( iOrderOpenStatus < 0 )

 

{

 

iErrorNumber = GetLastError();

 

strErrorMessage = ErrorDescription(iErrorNumber);

 

Alert( "OrderSend Failed: ", strErrorMessage );

 

iAttempts=0;

 

 

 

while (iOrderOpenStatus < 0)

 

{

 

Alert("Retrying sell order... " + iAttempts);

 

RefreshRates();

 

//modified 20090504

 

//iOrderOpenStatus = OrderSend(Symbol(),OP_SELL,dLots,Bid,iSlippage,dSellStopLoss,dSellTakeProfit,"BBTrendShift_Sell_"+Symbol()+"_"+Period(),iMagicNumber,0,Black);

 

iOrderOpenStatus = OrderSend(Symbol(),OP_SELL,dLots,Bid,0,0,0,"HeikenAshiTrend_Sell_"+Symbol()+"_"+Period(),iMagicNumber,0,Black);

 

iAttempts++;

 

Sleep(35000);

 

 

 

if (iAttempts==10)

 

{

 

iOrderOpenStatus=0;

 

Alert("Sell order failed after 10 attempts");

 

}

 

 

 

}

 

 

 

} // end of if iOrderOpenStatus

 

 

 

//modified 20090504

 

 

 

if ( iOrderOpenStatus > 0 )

 

{

 

 

 

if ( OrderSelect(iOrderOpenStatus,SELECT_BY_TICKET)==true )

 

{

 

RefreshRates();

 

dSellStopLoss = (Bid+(dStopLoss*(Point*pip)));

 

dSellTakeProfit = (Bid-(dTakeProfit*(Point*pip)));

 

bOrderModifyStatus = OrderModify(OrderTicket(),OrderOpenPrice(),dSellStopLoss,dSellTakeProfit, 0, Green);

 

if( bOrderModifyStatus == false )

 

{

 

iErrorNumber = GetLastError();

 

strErrorMessage = ErrorDescription(iErrorNumber);

 

Alert( "Order Modify Failed: ", strErrorMessage );

 

iAttempts=0;

 

 

 

while (bOrderModifyStatus == false)

 

{

 

Alert("Retrying order modify.");

 

RefreshRates();

 

dSellStopLoss = (Bid+(dStopLoss*(Point*pip)));

 

dSellTakeProfit = (Bid-(dTakeProfit*(Point*pip)));

 

bOrderModifyStatus = OrderModify(OrderTicket(),OrderOpenPrice(),dSellStopLoss,dSellTakeProfit, 0, Green);

 

iAttempts++;

 

Sleep(35000);

 

 

 

if (iAttempts==10)

 

{

 

bOrderModifyStatus=true;

 

Alert("Modify order failed after 10 attempts");

 

}

 

 

 

}

 

return;

 

 

 

} else { // end of if bOrderCloseStatus

 

Print ("Sell order modified.");

 

//iTotalSelectedTrades=0;

 

}

 

}

 

}

 

 

 

//end modified 20090504

 

 

 

return;

 

 

 

} // end of if iOpenSellSignal

 

 

 

if( (iTradeSignal == iCloseBuySignal) || (iTradeSignal == iCloseSellSignal) )

 

{

 

iTotalTrades = OrdersTotal();

 

 

 

for(int pos=0;pos<iTotalTrades;pos++)

 

{

 

 

 

if(OrderSelect(pos,SELECT_BY_POS)==false)

 

continue;

 

if( (( OrderSymbol() == Symbol() ) ) && (( OrderMagicNumber() == iMagicNumber ) ) )

 

{

 

if( OrderType() == OP_BUY )

 

{

 

RefreshRates();

 

bOrderCloseStatus = OrderClose( OrderTicket(), OrderLots(), Bid, iSlippage, Red );

 

 

 

if( bOrderCloseStatus == false )

 

{

 

iErrorNumber = GetLastError();

 

strErrorMessage = ErrorDescription(iErrorNumber);

 

Alert( "OrderClose Failed: ", strErrorMessage );

 

iAttempts=0;

 

 

 

while (bOrderCloseStatus == false)

 

{

 

Alert("Retrying order close.");

 

RefreshRates();

 

bOrderCloseStatus = OrderClose( OrderTicket(), OrderLots(), Bid, iSlippage, Red );

 

iAttempts++;

 

Sleep(35000);

 

 

 

if (iAttempts==10)

 

{

 

bOrderCloseStatus=true;

 

Alert("Close order failed after 10 attempts");

 

}

 

 

 

}

 

return;

 

} else { // end of if bOrderCloseStatus

 

Print ("Buy order closed.");

 

iTotalSelectedTrades=0;

 

}

 

} // end of if OP_BUY

 

 

 

if( OrderType() == OP_SELL )

 

{

 

RefreshRates();

 

bOrderCloseStatus = OrderClose( OrderTicket(), OrderLots(), Ask, iSlippage, Red );

 

 

 

if( bOrderCloseStatus == false )

 

{

 

iErrorNumber = GetLastError();

 

strErrorMessage = ErrorDescription(iErrorNumber);

 

Alert( "OrderClose Failed: ", strErrorMessage );

 

iAttempts=0;

 

 

 

while (bOrderCloseStatus == false)

 

{

 

Alert("Retrying order close.");

 

RefreshRates();

 

bOrderCloseStatus = OrderClose( OrderTicket(), OrderLots(), Ask, iSlippage, Red );

 

iAttempts++;

 

Sleep(35000);

 

 

 

if (iAttempts==10)

 

{

 

bOrderCloseStatus=true;

 

Alert("Close order failed after 10 attempts");

 

}

 

 

 

}

 

return;

 

} else { // end of if bOrderCloseStatus

 

Print ("Sell order closed.");

 

iTotalSelectedTrades=0;

 

}

 

} // end of if OP_SELL

 

 

 

} // end of if sysmbol

 

} // end of OrderSelect for loop

 

} // end of if iCloseBuySignal

 

} // end of fnOrder

Link to comment
Share on other sites

I am working on a system that requires using a multi time frame version of the indicator that triggers the trades in this EA.

It is a Heiken Ashi smoothed MTF. I trade a basket from an offline chart of 14 pairs. I also have a script of the order entry for this already. Would it be possible to make a new version based on this EA that changes the indicator to the MTF version and uses the basket order entry or would I need to make a new EA from scratch? I will post the indicator and entry script below.

Link to comment
Share on other sites

Heiken Ashi Smoothed MTF

 

//+------------------------------------------------------------------+

//| Heiken Ashi Smoothed.mq4 |

//+------------------------------------------------------------------+

//| mod by Raff |

//+------------------------------------------------------------------+

//mod2008fxtsd mtf ki

#property copyright "Copyright © 2006, Forex-TSD.com "

#property link "http://www.forex-tsd.com/"

 

#property indicator_chart_window

#property indicator_buffers 4

#property indicator_color1 Red

#property indicator_color2 DodgerBlue

#property indicator_color3 Red

#property indicator_color4 DodgerBlue

#property indicator_width1 1

#property indicator_width2 1

#property indicator_width3 3

#property indicator_width4 3

 

//---- parameters

 

extern int MaPeriod = 6;

extern int MaMetod = 2;

 

extern int MaPeriod2 = 2;

extern int MaMetod2 = 3;

 

extern bool DrawHisto = true;

 

extern int TimeFrame = 0;

extern string note_TimeFrames = "M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN|0-CurrentTF";

extern string note_MA_Method = "SMA0 EMA1 SMMA2 LWMA3";

string IndicatorFileName;

 

//---- buffers

double ExtMapBuffer1[];

double ExtMapBuffer2[];

double ExtMapBuffer3[];

double ExtMapBuffer4[];

double ExtMapBuffer5[];

double ExtMapBuffer6[];

double ExtMapBuffer7[];

double ExtMapBuffer8[];

 

 

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//|------------------------------------------------------------------|

int init()

{

//---- indicators

IndicatorBuffers(8);

if (DrawHisto)

{

SetIndexStyle(0,DRAW_HISTOGRAM);

SetIndexStyle(1,DRAW_HISTOGRAM);

SetIndexStyle(2,DRAW_HISTOGRAM);

SetIndexStyle(3,DRAW_HISTOGRAM);

}

else

{

SetIndexStyle(0,DRAW_SECTION);

SetIndexStyle(1,DRAW_SECTION);

SetIndexStyle(2,DRAW_SECTION);

SetIndexStyle(3,DRAW_SECTION);

}

SetIndexBuffer(0, ExtMapBuffer1);

SetIndexBuffer(1, ExtMapBuffer2);

SetIndexBuffer(2, ExtMapBuffer3);

SetIndexBuffer(3, ExtMapBuffer4);

//----

SetIndexDrawBegin(0,5);

//---- indicator buffers mapping

 

SetIndexBuffer(4,ExtMapBuffer5);

SetIndexBuffer(5,ExtMapBuffer6);

SetIndexBuffer(6,ExtMapBuffer7);

SetIndexBuffer(7,ExtMapBuffer8);

//---- initialization done

 

 

switch(TimeFrame)

{

case 1: string TimeFrameStr = "M1" ; break;

case 5 : TimeFrameStr = "M5" ; break;

case 15 : TimeFrameStr = "M15"; break;

case 30 : TimeFrameStr = "M30"; break;

case 60 : TimeFrameStr = "H1" ; break;

case 240 : TimeFrameStr = "H4" ; break;

case 1440 : TimeFrameStr = "D1" ; break;

case 10080 : TimeFrameStr = "W1" ; break;

case 43200 : TimeFrameStr = "MN1"; break;

default : TimeFrameStr = "TF0";

}

 

 

IndicatorShortName("HAMA ["+TimeFrameStr+"] ("

+MaPeriod+","+MaMetod+" | "+MaPeriod2+","+MaMetod2+")");

 

IndicatorFileName = WindowExpertName();

if (TimeFrame < Period()) TimeFrame = Period();

 

return(0);

}

//+------------------------------------------------------------------+

//| Custor indicator deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//---- TODO: add your code here

 

 

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator iteration function |

//+------------------------------------------------------------------+

int start()

{

int counted_bars=IndicatorCounted();

int i,limit;

 

if (counted_bars<0) return(-1);

if (counted_bars>0) counted_bars--;

 

limit=Bars-counted_bars;

 

if (TimeFrame != Period())

{

datetime TimeArray[];

limit = MathMax(limit,TimeFrame/Period());

ArrayCopySeries(TimeArray ,MODE_TIME ,NULL,TimeFrame);

 

for(i=0,int y=0; i<limit; i++)

{

if(Time<TimeArray[y]) y++;

 

ExtMapBuffer1 = iCustom(NULL,TimeFrame,IndicatorFileName,

MaPeriod,MaMetod,MaPeriod2,MaMetod2,DrawHisto,0,y);

ExtMapBuffer2 = iCustom(NULL,TimeFrame,IndicatorFileName,

MaPeriod,MaMetod,MaPeriod2,MaMetod2,DrawHisto,1,y);

ExtMapBuffer3 = iCustom(NULL,TimeFrame,IndicatorFileName,

MaPeriod,MaMetod,MaPeriod2,MaMetod2,DrawHisto,2,y);

ExtMapBuffer4 = iCustom(NULL,TimeFrame,IndicatorFileName,

MaPeriod,MaMetod,MaPeriod2,MaMetod2,DrawHisto,3,y);

 

}

return(0);

}

 

double maOpen, maClose, maLow, maHigh;

double haOpen, haHigh, haLow, haClose;

 

 

limit= MathMax(limit,MaPeriod);

limit= MathMax(limit,MaPeriod2);

 

for (i=limit;i>=0;i--)

 

{

 

maOpen=iMA(NULL,0,MaPeriod,0,MaMetod,MODE_OPEN,i);

maClose=iMA(NULL,0,MaPeriod,0,MaMetod,MODE_CLOSE,i);

maLow=iMA(NULL,0,MaPeriod,0,MaMetod,MODE_LOW,i);

maHigh=iMA(NULL,0,MaPeriod,0,MaMetod,MODE_HIGH,i);

 

haOpen=(ExtMapBuffer5[i+1]+ExtMapBuffer6[i+1])/2;

haClose=(maOpen+maHigh+maLow+maClose)/4;

haHigh=MathMax(maHigh, MathMax(haOpen, haClose));

haLow=MathMin(maLow, MathMin(haOpen, haClose));

 

if (haOpen<haClose)

{

ExtMapBuffer7=haLow;

ExtMapBuffer8=haHigh;

}

else

{

ExtMapBuffer7=haHigh;

ExtMapBuffer8=haLow;

}

ExtMapBuffer5=haOpen;

ExtMapBuffer6=haClose;

 

}

 

 

for(y=0,i=0; i<limit; i++)

 

{

 

ExtMapBuffer1=iMAOnArray(ExtMapBuffer7,0,MaPeriod2,0,MaMetod2,i);

ExtMapBuffer2=iMAOnArray(ExtMapBuffer8,0,MaPeriod2,0,MaMetod2,i);

ExtMapBuffer3=iMAOnArray(ExtMapBuffer5,0,MaPeriod2,0,MaMetod2,i);

ExtMapBuffer4=iMAOnArray(ExtMapBuffer6,0,MaPeriod2,0,MaMetod2,i);

 

}

 

//----

return(0);

}

//+------------------------------------------------------------------+

Link to comment
Share on other sites

Buy Script

 

//+------------------------------------------------------------------+

//| mIBFXHedge |

//| Copyright © 2008, Julius Figueroa |

//| [email protected] |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2008, Julius Figueroa"

#property link "[email protected]"

 

#property show_inputs

#include <WinUser32.mqh>

#include <stdlib.mqh>

 

extern double Lot = 0.02;

extern int MagicNumber=71946723;

extern string TradeComment="";

 

 

bool CheckIfTradeAlreadyExists(string symbol)

{

if (OrdersTotal()==0) return(false);

for (int cc=0; cc<OrdersTotal();cc++)

{

OrderSelect(cc, SELECT_BY_POS);

if (OrderSymbol()==symbol && OrderMagicNumber()==MagicNumber) return(true);

}

return(false);

 

}// end bool CheckTrendExists()

 

//+------------------------------------------------------------------+

//| script program start function |

//+------------------------------------------------------------------+

int start()

{

 

int TradesSent=0;

 

bool TradeExists = CheckIfTradeAlreadyExists("GBPUSDfx");

if (!TradeExists) int ticket = OrderSend("GBPUSDfx",OP_BUY, Lot, MarketInfo("GBPUSDfx",MODE_ASK), 2, NULL, NULL, TradeComment, MagicNumber, 0, CLR_NONE);

if (ticket > -1) TradesSent++;

 

TradeExists = CheckIfTradeAlreadyExists("EURGBPfx");

if (!TradeExists) ticket = OrderSend("EURGBPfx",OP_BUY, Lot, MarketInfo("EURGBPfx",MODE_ASK), 2, NULL, NULL, TradeComment, MagicNumber, 0, CLR_NONE);

if (ticket > -1) TradesSent++;

 

TradeExists = CheckIfTradeAlreadyExists("GBPCHFfx");

if (!TradeExists) ticket = OrderSend("GBPCHFfx",OP_BUY, Lot, MarketInfo("GBPCHFfx",MODE_ASK), 2, NULL, NULL, TradeComment, MagicNumber, 0, CLR_NONE);

if (ticket > -1) TradesSent++;

 

TradeExists = CheckIfTradeAlreadyExists("CHFJPYfx");

if (!TradeExists) ticket = OrderSend("CHFJPYfx",OP_BUY, Lot, MarketInfo("CHFJPYfx",MODE_ASK), 2, NULL, NULL, TradeComment, MagicNumber, 0, CLR_NONE);

if (ticket > -1) TradesSent++;

 

TradeExists = CheckIfTradeAlreadyExists("AUDJPYfx");

if (!TradeExists) ticket = OrderSend("AUDJPYfx",OP_BUY, Lot, MarketInfo("AUDJPYfx",MODE_ASK), 2, NULL, NULL, TradeComment, MagicNumber, 0, CLR_NONE);

if (ticket > -1) TradesSent++;

 

TradeExists = CheckIfTradeAlreadyExists("EURJPYfx");

if (!TradeExists) ticket = OrderSend("EURJPYfx",OP_BUY, Lot, MarketInfo("EURJPYfx",MODE_ASK), 2, NULL, NULL, TradeComment, MagicNumber, 0, CLR_NONE);

if (ticket > -1) TradesSent++;

 

TradeExists = CheckIfTradeAlreadyExists("USDCHFfx");

if (!TradeExists) ticket = OrderSend("USDCHFfx",OP_BUY, Lot, MarketInfo("USDCHFfx",MODE_ASK), 2, NULL, NULL, TradeComment, MagicNumber, 0, CLR_NONE);

if (ticket > -1) TradesSent++;

 

 

 

TradeExists = CheckIfTradeAlreadyExists("NZDJPYfx");

if (!TradeExists) ticket = OrderSend("NZDJPYfx",OP_BUY, Lot, MarketInfo("NZDJPYfx",MODE_ASK), 2, NULL, NULL, TradeComment, MagicNumber, 0, CLR_NONE);

if (ticket > -1) TradesSent++;

 

TradeExists = CheckIfTradeAlreadyExists("AUDUSDfx");

if (!TradeExists) ticket = OrderSend("AUDUSDfx",OP_BUY, Lot, MarketInfo("AUDUSDfx",MODE_ASK), 2, NULL, NULL, TradeComment, MagicNumber, 0, CLR_NONE);

if (ticket > -1) TradesSent++;

 

TradeExists = CheckIfTradeAlreadyExists("USDJPYfx");

if (!TradeExists) ticket = OrderSend("USDJPYfx",OP_BUY, Lot, MarketInfo("USDJPYfx",MODE_ASK), 2, NULL, NULL, TradeComment, MagicNumber, 0, CLR_NONE);

if (ticket > -1) TradesSent++;

 

TradeExists = CheckIfTradeAlreadyExists("EURUSDfx");

if (!TradeExists) ticket = OrderSend("EURUSDfx",OP_BUY, Lot, MarketInfo("EURUSDfx",MODE_ASK), 2, NULL, NULL, TradeComment, MagicNumber, 0, CLR_NONE);

if (ticket > -1) TradesSent++;

 

TradeExists = CheckIfTradeAlreadyExists("EURCHFfx");

if (!TradeExists) ticket = OrderSend("EURCHFfx",OP_BUY, Lot, MarketInfo("EURCHFfx",MODE_ASK), 2, NULL, NULL, TradeComment, MagicNumber, 0, CLR_NONE);

if (ticket > -1) TradesSent++;

 

TradeExists = CheckIfTradeAlreadyExists("GBPJPYfx");

if (!TradeExists) ticket = OrderSend("GBPJPYfx",OP_BUY, Lot, MarketInfo("GBPJPYfx",MODE_ASK), 2, NULL, NULL, TradeComment, MagicNumber, 0, CLR_NONE);

if (ticket > -1) TradesSent++;

 

TradeExists = CheckIfTradeAlreadyExists("NZDUSDfx");

if (!TradeExists) ticket = OrderSend("NZDUSDfx",OP_BUY, Lot, MarketInfo("NZDUSDfx",MODE_ASK), 2, NULL, NULL, TradeComment, MagicNumber, 0, CLR_NONE);

if (ticket > -1) TradesSent++;

 

 

MessageBox("This script opened " + TradesSent + " trades.","Information");

 

return(0);

}

//+------------------------------------------------------------------+

Link to comment
Share on other sites

//+------------------------------------------------------------------+

//| mIBFXHedge |

//| Copyright © 2008, Julius Figueroa |

//| [email protected] |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2008, Julius Figueroa"

#property link "[email protected]"

 

#property show_inputs

#include <WinUser32.mqh>

#include <stdlib.mqh>

 

extern double Lot = 0.02;

extern int MagicNumber=71946723;

extern string TradeComment="";

 

 

bool CheckIfTradeAlreadyExists(string symbol)

{

if (OrdersTotal()==0) return(false);

for (int cc=0; cc<OrdersTotal();cc++)

{

OrderSelect(cc, SELECT_BY_POS);

if (OrderSymbol()==symbol && OrderMagicNumber()==MagicNumber) return(true);

}

return(false);

 

}// end bool CheckTrendExists()

 

//+------------------------------------------------------------------+

//| script program start function |

//+------------------------------------------------------------------+

int start()

{

 

int TradesSent=0;

 

bool TradeExists = CheckIfTradeAlreadyExists("GBPUSDfx");

if (!TradeExists) int ticket = OrderSend("GBPUSDfx",OP_SELL, Lot, MarketInfo("GBPUSDfx",MODE_BID), 2, NULL, NULL, TradeComment, MagicNumber, 0, CLR_NONE);

if (ticket > -1) TradesSent++;

 

TradeExists = CheckIfTradeAlreadyExists("EURGBPfx");

if (!TradeExists) ticket = OrderSend("EURGBPfx",OP_SELL, Lot, MarketInfo("EURGBPfx",MODE_BID), 2, NULL, NULL, TradeComment, MagicNumber, 0, CLR_NONE);

if (ticket > -1) TradesSent++;

 

TradeExists = CheckIfTradeAlreadyExists("GBPCHFfx");

if (!TradeExists) ticket = OrderSend("GBPCHFfx",OP_SELL, Lot, MarketInfo("GBPCHFfx",MODE_BID), 2, NULL, NULL, TradeComment, MagicNumber, 0, CLR_NONE);

if (ticket > -1) TradesSent++;

 

TradeExists = CheckIfTradeAlreadyExists("CHFJPYfx");

if (!TradeExists) ticket = OrderSend("CHFJPYfx",OP_SELL, Lot, MarketInfo("CHFJPYfx",MODE_BID), 2, NULL, NULL, TradeComment, MagicNumber, 0, CLR_NONE);

if (ticket > -1) TradesSent++;

 

TradeExists = CheckIfTradeAlreadyExists("AUDJPYfx");

if (!TradeExists) ticket = OrderSend("AUDJPYfx",OP_SELL, Lot, MarketInfo("AUDJPYfx",MODE_BID), 2, NULL, NULL, TradeComment, MagicNumber, 0, CLR_NONE);

if (ticket > -1) TradesSent++;

 

TradeExists = CheckIfTradeAlreadyExists("EURJPYfx");

if (!TradeExists) ticket = OrderSend("EURJPYfx",OP_SELL, Lot, MarketInfo("EURJPYfx",MODE_BID), 2, NULL, NULL, TradeComment, MagicNumber, 0, CLR_NONE);

if (ticket > -1) TradesSent++;

 

TradeExists = CheckIfTradeAlreadyExists("USDCHFfx");

if (!TradeExists) ticket = OrderSend("USDCHFfx",OP_SELL, Lot, MarketInfo("USDCHFfx",MODE_BID), 2, NULL, NULL, TradeComment, MagicNumber, 0, CLR_NONE);

if (ticket > -1) TradesSent++;

 

 

 

TradeExists = CheckIfTradeAlreadyExists("NZDJPYfx");

if (!TradeExists) ticket = OrderSend("NZDJPYfx",OP_SELL, Lot, MarketInfo("NZDJPYfx",MODE_BID), 2, NULL, NULL, TradeComment, MagicNumber, 0, CLR_NONE);

if (ticket > -1) TradesSent++;

 

TradeExists = CheckIfTradeAlreadyExists("AUDUSDfx");

if (!TradeExists) ticket = OrderSend("AUDUSDfx",OP_SELL, Lot, MarketInfo("AUDUSDfx",MODE_BID), 2, NULL, NULL, TradeComment, MagicNumber, 0, CLR_NONE);

if (ticket > -1) TradesSent++;

 

TradeExists = CheckIfTradeAlreadyExists("USDJPYfx");

if (!TradeExists) ticket = OrderSend("USDJPYfx",OP_SELL, Lot, MarketInfo("USDJPYfx",MODE_BID), 2, NULL, NULL, TradeComment, MagicNumber, 0, CLR_NONE);

if (ticket > -1) TradesSent++;

 

TradeExists = CheckIfTradeAlreadyExists("EURUSDfx");

if (!TradeExists) ticket = OrderSend("EURUSDfx",OP_SELL, Lot, MarketInfo("EURUSDfx",MODE_BID), 2, NULL, NULL, TradeComment, MagicNumber, 0, CLR_NONE);

if (ticket > -1) TradesSent++;

 

TradeExists = CheckIfTradeAlreadyExists("EURCHFfx");

if (!TradeExists) ticket = OrderSend("EURCHFfx",OP_SELL, Lot, MarketInfo("EURCHFfx",MODE_BID), 2, NULL, NULL, TradeComment, MagicNumber, 0, CLR_NONE);

if (ticket > -1) TradesSent++;

 

TradeExists = CheckIfTradeAlreadyExists("GBPJPYfx");

if (!TradeExists) ticket = OrderSend("GBPJPYfx",OP_SELL, Lot, MarketInfo("GBPJPYfxfx",MODE_BID), 2, NULL, NULL, TradeComment, MagicNumber, 0, CLR_NONE);

if (ticket > -1) TradesSent++;

 

TradeExists = CheckIfTradeAlreadyExists("NZDUSD");

if (!TradeExists) ticket = OrderSend("NZDUSDfx",OP_SELL, Lot, MarketInfo("NZDUSDfx",MODE_BID), 2, NULL, NULL, TradeComment, MagicNumber, 0, CLR_NONE);

if (ticket > -1) TradesSent++;

 

 

MessageBox("This script opened " + TradesSent + " trades.","Information");

 

return(0);

}

//+------------------------------------------------------------------+

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...