BARROW BOY, PLEASE CAN YOU HELP ME CHECK OUT THIS CODE?

 

hi Barrow boy,

I would be most grate full if you can help me with the code below.i have written some line but am not experienced in progamming,I would be most happy if you can help me look at it and correct any mistakes.

As can been seen in the code below(I hope it is clear enough).the idea is based on using a displaced simple moving average with a period of 5 and positive shift of 2.

for buy signals, the the difference between the dma value and the closing price of the security should be less than or equl toa certain number(for now I am experimenting with 22) and for sell signal, the diference ahould be greater than or equal that number.the maximum number open position should not exceed one.this should be part of the criteria for opening a postion.

An open buy trade should be closed when conditions for a sell trade(as mention above) exists conversely,a sell tposition should be closed when conditions for buy trade exists

I have difficulty in writting the following codes snipet for the EA:

1) code for verifying that an opnem position exist

2)code for closing an open postion

3)code for opening a positons when the conditions are met.

Thanks in advance.

Malachy

//+------------------------------------------------------------------+
//| DMA
//| Copyright © 2008, malachy
//|
//+------------------------------------------------------------------+


extern double Lots = 0.1;
extern int diffsell=+22;
extern int diffbuy=-22;


//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
double ma_val; // value of displaced moving simple moving average
int total; // max order
int ticket;

ma_val=iMA( NULL,0,5,2,0,0,0); // data been put into external variables for easy manipulation


// now lets check for open position and close it if the conditions for exiting exists

total=OrdersTotal();

if (total >= 1 && ma_val - PRICE_CLOSE >= diffsell)

{
OrderClose(ticket,1,Ask,1,Red);
return(0);
} //close buy trade

if (total >= 1 && ma_val - PRICE_CLOSE <= diffsell)

{
OrderClose(ticket,1,Bid,1,Red);
return(0); //close sell trade


if (total <= 0 && ma_val - PRICE_CLOSE <= -22) // check for long possibility
{
OrderSend(Symbol(),OP_BUY,1,Ask, 5,0,0,NULL, 9055500, 0,Green);
}

// buy!
if (total >= 0 && ma_val - PRICE_CLOSE >= +22) // check for short possibility

{
ticket=OrderSend(Symbol(),OP_SELL, 1, Bid, 5,0,0,NULL, 9103525,0,Green); //sell!
}



return(0);
}

}

// the end.

 

NF

Cant say I got the logic on this - and there were so many code issues, I could only tidy it up so it runs...

FWIW

-BB-

//+------------------------------------------------------------------+
//| DMA
//| Copyright © 2008, malachy
//|
//+------------------------------------------------------------------+


extern double Lots = 0.1;
extern int diffsell=+22;
extern int diffbuy=-22;
extern int MagicNumber=9055500;


//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
double ma_val; // value of displaced moving simple moving average
int BuyNum, SellNum; // max order
int ticket;

ma_val=iMA( NULL,0,5,2,0,0,0); // data been put into external variables for easy manipulation


// now lets check for open position and close it if the conditions for exiting exists

BuyNum = OpenTradesForMNandType(MagicNumber, OP_BUY);
SellNum = OpenTradesForMNandType(MagicNumber, OP_SELL);

if (BuyNum >= 1 && (ma_val - Close[0]) >= diffsell*Point) CloseAllBuyOrders(MagicNumber);

if (SellNum >= 1 && (ma_val - Close[0]) <= diffsell*Point) CloseAllSellOrders(MagicNumber);



// Check again after possible closures
BuyNum = OpenTradesForMNandType(MagicNumber, OP_BUY);
SellNum = OpenTradesForMNandType(MagicNumber, OP_SELL);

if (BuyNum == 0 && (ma_val - Close[0]) <= diffbuy*Point) // check for long possibility
{
OrderSend(Symbol(),OP_BUY,1,Ask, 5,0,0,NULL, MagicNumber , 0,Blue);
}

//
if (SellNum == 0 && (ma_val - Close[0]) >= diffsell*Point) // check for short possibility

{
ticket=OrderSend(Symbol(),OP_SELL, 1, Bid, 5,0,0,NULL, MagicNumber,0,Red); //sell!
}



return(0);


}

  void CloseAllBuyOrders(int MN)
  {
  int i, iTotalOrders;
  
  //iTotalOrders=OrdersTotal(); 
  //for (i=0; i<iTotalOrders; i++)
   
   iTotalOrders=OrdersTotal()-1; // Rosh line
  
   for (i=iTotalOrders; i>=0; i--) // Rosh line     
   
   { 
      if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      { 
         if (OrderMagicNumber()==MN)
         { 
            if (OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),Bid,5,Violet);
            if (OrderType()==OP_BUYSTOP) OrderDelete(OrderTicket());
            if (OrderType()==OP_BUYLIMIT) OrderDelete(OrderTicket());
            
         }
      }
   }
}

  void CloseAllSellOrders(int MN)
  {
  int i, iTotalOrders;
  
  // iTotalOrders=OrdersTotal(); 
  // for (i=0; i<iTotalOrders; i++)
   
   iTotalOrders=OrdersTotal()-1; // Rosh line
  
   for (i=iTotalOrders; i>=0; i--) // Rosh line  
   { 
      if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      { 
         if (OrderMagicNumber()==MN)
         { 
            if (OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),Ask,5,Violet);
            if (OrderType()==OP_SELLSTOP) OrderDelete(OrderTicket());
            if (OrderType()==OP_SELLLIMIT) OrderDelete(OrderTicket());
         }
      }
   }
}

int OpenTradesForMNandType(int iMN, int iType)
{
// Counts orders by MagicNumber and OrderType 
int icnt, itotal, retval;

retval=0;
itotal=OrdersTotal();

   for(icnt=0;icnt<itotal;icnt++)
     {
      OrderSelect(icnt, SELECT_BY_POS, MODE_TRADES);
       // check for opened position, symbol & MagicNumber
      if(OrderType()==iType)  
        {
         if(OrderMagicNumber()==iMN)
         {
           retval++;
        
           //Print("Orders opened : ",retval);
         }
        }
     }

return(retval);
}


// the end. 
 
BarrowBoy wrote >>

NF

Cant say I got the logic on this - and there were so many code issues, I could only tidy it up so it runs...

FWIW

-BB-

Thanks Barrow boy.I really appreciate the time you spent.You must be an angel to do all that work for someone.

I will run it and test it over the next few weeks.

If you don't mind,Can I have a way of contacting you other than thiis forum?.It seems like common sense for me to get close to someone gifted like u.

Thanks a zillion.

Malachy

 

M

> Angel?

No way, my partner really is an angel though :)

Many people helped me early on, so what goes around can sometimes come around, even in Forex!

> I will run it and test it over the next few weeks

Dont hold your breath & dont use this on a live account, its not ready

> Can I have a way of contacting you other than this forum?

Public domain (i.e. free) support is here on an as available basis, same as the other net contributors here, otherwise its

http://www.selectfx.net/customquotes1.htm

Good luck

-BB-

 
BarrowBoy wrote >>

M

> Angel?

No way, my partner really is an angel though :)

Many people helped me early on, so what goes around can sometimes come around, even in Forex!

> I will run it and test it over the next few weeks

Dont hold your breath & dont use this on a live account, its not ready

> Can I have a way of contacting you other than this forum?

Public domain (i.e. free) support is here on an as available basis, same as the other net contributors here, otherwise its

http://www.selectfx.net/customquotes1.htm

Good luck

-BB-

Hi BarrowBoy,

Thanks over and over again for your help/I have since you work on the code I have been trying it out on the different time frame.I noticed it seems to work better on higher time frames(15 minutes and above---thats if I am not rushing to fast to conclusions).Also every body knows, anty tbding system does badly in a flat market.same is true with this EA.So I decided may be Adx should be added to it to so that it does not trade when there is no positive increment in adx reading9thats no position should be taken if Adx is going down). Studing Adx for soe time now,i have ome to the conclusion that there is no fixed Adx value that shows a trend/the common idea that Adx should have risen above a certain value before can be taken is misleadin9at least to my own observation.)what could be helpful is been able to know when adx hax changed by x vlues in the postive direction(upwards).My idea is that the value of Adx using the open of a security should be subtracted form the value of its close.If the result is above a cetain positivevalue(lets call it X although in the code below I put 2)

(adxopen =iADX(NULL,0,frame,0,MODE_MAIN,0); // Adx value when the secutity opens

adxclose =iADX(NULL,0,frame,1,MODE_MAIN,0);// Adx vAlue when the security closes

diffadx=(adxclose-adxopen); //difference in Adx values)

and the other conditions of the trade exist, then it is more likely that the trade would be a trend.Below is the code i have included in the codes you modified for me.I would be most grateful if you could incoporate this Adx idea into the code for me.

below is the complete code(the one you modified for me with the Adx code idea added)'

looking forward to hearing from you.My email is: enabu2000@yahoo,com

My phone number is 4168290502;

I live in toronto canad

thanks,

malachy

//+------------------------------------------------------------------+
//| DMA
//| Copyright © 2008, malachy
//|
//+------------------------------------------------------------------+


extern double Lots = 0.01;
extern int diffsell=+3;
extern int diffbuy=-3;
extern int MagicNumber=9055500;
extern double frame=14;
double diffadx;


//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
double ma_val; // value of displaced moving simple moving average
int BuyNum, SellNum; // max order
int ticket;
double adxopen;
double adxclose;


ma_val=iMA( NULL,0,5,2,0,0,0); // data been put into external variables for easy manipulation

adxopen =iADX(NULL,0,frame,0,MODE_MAIN,0); // Adx value when the secutity opens

adxclose =iADX(NULL,0,frame,1,MODE_MAIN,0);// Adx vlue when the security closes

diffadx=(adxclose-adxopen); //difference in dx values


// now lets check for open position and close it if the conditions for exiting exists

BuyNum = OpenTradesForMNandType(MagicNumber, OP_BUY);
SellNum = OpenTradesForMNandType(MagicNumber, OP_SELL);

if (BuyNum >=1 && (ma_val - Close[0]) >= diffsell*Point) CloseAllBuyOrders(MagicNumber);

if (SellNum >=1 && (ma_val - Close[0]) <= diffbuy*Point) CloseAllSellOrders(MagicNumber);

// Check again after possible closures
BuyNum = OpenTradesForMNandType(MagicNumber, OP_BUY);
SellNum = OpenTradesForMNandType(MagicNumber, OP_SELL);

if (BuyNum == 0 && (ma_val - Close[0]) <= diffbuy*Point && diffadx>=2) // check for long possibility
{
OrderSend(Symbol(),OP_BUY,Lots,Ask, 2,0,0,NULL, MagicNumber, 0,Blue);
}

//
if (SellNum ==0 && (ma_val - Close[0]) >= diffsell*Point && diffadx>=2) // check for short possibility

{
ticket=OrderSend(Symbol(),OP_SELL, Lots, Bid, 2,0,0,NULL, MagicNumber,0,Red); //sell!
}

return(0);


}

void CloseAllBuyOrders(int MN)
{
int i, iTotalOrders;

//iTotalOrders=OrdersTotal();
//for (i=0; i<iTotalOrders; i++)

iTotalOrders=OrdersTotal()-1; // Rosh line

for (i=iTotalOrders; i>=0; i--) // Rosh line

{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderMagicNumber()==MN)
{
if (OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),Bid,5,Violet);
if (OrderType()==OP_BUYSTOP) OrderDelete(OrderTicket());
if (OrderType()==OP_BUYLIMIT) OrderDelete(OrderTicket());

}
}
}
}

void CloseAllSellOrders(int MN)
{
int i, iTotalOrders;

// iTotalOrders=OrdersTotal();
// for (i=0; i<iTotalOrders; i++)

iTotalOrders=OrdersTotal()-1; // Rosh line

for (i=iTotalOrders; i>=0; i--) // Rosh line
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderMagicNumber()==MN)
{
if (OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),Ask,5,Violet);
if (OrderType()==OP_SELLSTOP) OrderDelete(OrderTicket());
if (OrderType()==OP_SELLLIMIT) OrderDelete(OrderTicket());
}
}
}
}

int OpenTradesForMNandType(int iMN, int iType)
{
// Counts orders by MagicNumber and OrderType
int icnt, itotal, retval;

retval=0;
itotal=OrdersTotal();

for(icnt=0;icnt<itotal;icnt++)
{
OrderSelect(icnt, SELECT_BY_POS, MODE_TRADES);
// check for opened position, symbol & MagicNumber
if(OrderType()==iType)
{
if(OrderMagicNumber()==iMN)
{
retval++;

//Print("Orders opened : ",retval);
}
}
}

return(retval);
}


// the end.

 

NF

> seems to work better on higher time frames

Systems generally are better in terms of reliability on the higher timeframes, even though max profit may derive from the lower ones (but with more drawdown & stress along the way!)

> ADX

Before I do that, check to see if ATR (Average True Range) might be better for go/no go on the trending system for the pair & timeframe?
Review and decide

-BB-

 
BarrowBoy wrote >>

NF

> seems to work better on higher time frames

Systems generally are better in terms of reliability on the higher timeframes, even though max profit may derive from the lower ones (but with more drawdown & stress along the way!)

> ADX

Before I do that, check to see if ATR (Average True Range) might be better for go/no go on the trending system for the pair & timeframe?
Review and decide

-BB-

Hi BB,

thanks once again for responding to my post.Honestly, I have never used the ATR before but would look at it and see if it can help me filter the the non trending trades.I really need to get this going.I have lost close to 20,000 on forex.I think An EA si what I need to trade Objectively.

If you know of any good EA, please let me know.I don't mind paying for it if it .I neeed to start making money in forex as I am almost penniless now.

thanks for everything,

Malachy

 

NF

I'd be reluctant to sell you an EA at present - I think you'd set the lot size & risk boost too high...

Unless I've missed something, I dont see any indication of pair or timeframe as the target for the system - and this is a concern...

Perhaps you have hopped from one pair to another and tried different timeframes and thats where the 20k went? :(

So... steps to move forward

1) Decide a market session, are you awake during Asian or European session?

2) Decide a pair - for a trending system, I would go AUDJPY for Asian session, EURJPY or GBPJPY for European

3) Decide a timeframe

4) Study ATR, StdDev & ADX until you know which is best for pair & timeframe for trend evaluation

Come back when you have the four answers - and take your time - for once...

Good Luck

-BB-

 
BarrowBoy wrote >>

NF

I'd be reluctant to sell you an EA at present - I think you'd set the lot size & risk boost too high...

Unless I've missed something, I dont see any indication of pair or timeframe as the target for the system - and this is a concern...

Perhaps you have hopped from one pair to another and tried different timeframes and thats where the 20k went? :(

So... steps to move forward

1) Decide a market session, are you awake during Asian or European session?

2) Decide a pair - for a trending system, I would go AUDJPY for Asian session, EURJPY or GBPJPY for European

3) Decide a timeframe

4) Study ATR, StdDev & ADX until you know which is best for pair & timeframe for trend evaluation

Come back when you have the four answers - and take your time - for once...

Good Luck

-BB-

Hi BB,

Thanks fot always taking the time to read and reply my post.Actually, the 20kI lost was lost using any EA.I ony recently found out about EA(been trading for a year now).You are right, i have been really bad with money management this is because I had huge financial responsibiliies and my good job was bad.so I unwittingly allowed my emotions to decide for me and thus overleveraged my account using strategyies i formulated that were not even tested.i was trying to meet up with my responsibility but ironically, my recklessness has made me far behind by a year.My attraction to EA is that it would allow me trade without emotions and also(even I now adhere to very, very strict money managemet rules).Also an EA wuld allow me do a regular job and also spend other times to patiently study fores more.

I am going to take your advice(which gives me an outline on how to find my bearing in forex)thie same time I would still appreciate it if you can selll me any Ea that has been proven to work.I would dmotrade it for a while b4 using on a live account.

Looking to hearing from you again.

cheers,

malachy

 

NF

Mail me with your broker name & live account type

support@selectfx.net

-BB-

 
BarrowBoy wrote >>

NF

Mail me with your broker name & live account type

support@selectfx.net

-BB-

nicefella31
wrote
>>

Hi BB,

Thanks fot always taking the time to read and reply my post.Actually, the 20kI lost was lost using any EA.I ony recently found out about EA(been trading for a year now).You are right, i have been really bad with money management this is because I had huge financial responsibiliies and my good job was bad.so I unwittingly allowed my emotions to decide for me and thus overleveraged my account using strategyies i formulated that were not even tested.i was trying to meet up with my responsibility but ironically, my recklessness has made me far behind by a year.My attraction to EA is that it would allow me trade without emotions and also(even I now adhere to very, very strict money managemet rules).Also an EA wuld allow me do a regular job and also spend other times to patiently study fores more.

I am going to take your advice(which gives me an outline on how to find my bearing in forex)thie same time I would still appreciate it if you can selll me any Ea that has been proven to work.I would dmotrade it for a while b4 using on a live account.

Looking to hearing from you again.

cheers,

malachy

hi BB,
i have sent you a mail at the email address you gave.
thanks,
malachy
Reason: