Who wants a challenge?

fxprotrader
Trader
Posts: 26
Joined: Sat Jun 16, 2012 11:26 pm

Who wants a challenge?

Post by fxprotrader »

I'm trying to code the following. This would be a Buy trade.
I have tried a for loop, a mess of if conditions and neither has produced results I'm looking for.
It appears to be simple but I have not been able to get it working.
You do not have the required permissions to view the files attached to this post.
Last edited by fxprotrader on Sun Sep 02, 2012 6:52 pm, edited 1 time in total.
User avatar
gaheitman
Trader
Posts: 655
Joined: Tue Nov 15, 2011 10:55 pm
Location: Richmond, VA, US

Re: Who wants a challenge?

Post by gaheitman »

fxprotrader wrote:I'm trying to code the following. This would be a Buy trade.
I have tried a for loop, a mess of if conditions and neither has produced result I'm looking for.
It appears to be simple but I have not been able to get it working.

Are you trying to put this in an EA?
fxprotrader
Trader
Posts: 26
Joined: Sat Jun 16, 2012 11:26 pm

Re: Who wants a challenge?

Post by fxprotrader »

gaheitman wrote:
fxprotrader wrote:I'm trying to code the following. This would be a Buy trade.
I have tried a for loop, a mess of if conditions and neither has produced result I'm looking for.
It appears to be simple but I have not been able to get it working.

Are you trying to put thin in an EA?
Sorry forgot to mention that but, yes.
User avatar
gaheitman
Trader
Posts: 655
Joined: Tue Nov 15, 2011 10:55 pm
Location: Richmond, VA, US

Re: Who wants a challenge?

Post by gaheitman »

fxprotrader wrote:
gaheitman wrote:
fxprotrader wrote:I'm trying to code the following. This would be a Buy trade.
I have tried a for loop, a mess of if conditions and neither has produced result I'm looking for.
It appears to be simple but I have not been able to get it working.

Are you trying to put thin in an EA?
Sorry forgot to mention that but, yes.
Are you entering after a bar closes? You can't know while a bar is open whether the low will stay above the MA or that the high will stay below MA+5.

How do you start trading, once a bar straddles the MA? How are you picking the direction?
fxprotrader
Trader
Posts: 26
Joined: Sat Jun 16, 2012 11:26 pm

Re: Who wants a challenge?

Post by fxprotrader »

Are you entering after a bar closes? You can't know while a bar is open whether the low will stay above the MA or that the high will stay below MA+5.

How do you start trading, once a bar straddles the MA? How are you picking the direction?
Yes, last closed as soon as the bar straddles the MA. The direction was picked on a higher timeframe. I'm using the buy as an example but as a rule if price moves from below the MA up through would always be a buy.

Also want to mention that if the high does not reach MA +5 within 5 bars, the 5th bar would be the last you could enter on.

The only code I need is after the last bar straddles the MA(last Blue arrow)
User avatar
gaheitman
Trader
Posts: 655
Joined: Tue Nov 15, 2011 10:55 pm
Location: Richmond, VA, US

Re: Who wants a challenge?

Post by gaheitman »

fxprotrader wrote:
Are you entering after a bar closes? You can't know while a bar is open whether the low will stay above the MA or that the high will stay below MA+5.

How do you start trading, once a bar straddles the MA? How are you picking the direction?
Yes, last closed as soon as the bar straddles the MA. The direction was picked on a higher timeframe. I'm using the buy as an example but as a rule if price moves from below the MA up through would always be a buy.

Also want to mention that if the high does not reach MA +5 within 5 bars, the 5th bar would be the last you could enter on.

The only code I need is after the last bar straddles the MA(last Blue arrow)
The code wouldn't be much different from what you are doing to enter your straddle trades, you are just looking for the Low[1] > MA && High[1] < MA+5 Pips. You'll have to keep track of the number of trades you enter and stop at 5 or when you hit one of the High/Low conditions.

If you post the code that is entering the first trades it would be easier to help....

George
fxprotrader
Trader
Posts: 26
Joined: Sat Jun 16, 2012 11:26 pm

Re: Who wants a challenge?

Post by fxprotrader »

gaheitman wrote:
fxprotrader wrote:
Are you entering after a bar closes? You can't know while a bar is open whether the low will stay above the MA or that the high will stay below MA+5.

How do you start trading, once a bar straddles the MA? How are you picking the direction?
Yes, last closed as soon as the bar straddles the MA. The direction was picked on a higher timeframe. I'm using the buy as an example but as a rule if price moves from below the MA up through would always be a buy.

Also want to mention that if the high does not reach MA +5 within 5 bars, the 5th bar would be the last you could enter on.

The only code I need is after the last bar straddles the MA(last Blue arrow)
The code wouldn't be much different from what you are doing to enter your straddle trades, you are just looking for the Low[1] > MA && High[1] < MA+5 Pips. You'll have to keep track of the number of trades you enter and stop at 5 or when you hit one of the High/Low conditions.

If you post the code that is entering the first trades it would be easier to help....

George

A clarification;there is a 5 pip, 5 bar window after the straddle bar and only 1 trade would be entered.

I have attached my test file.
What I have at this point is the straddle bar and the 1st after it. I'm marking with arrows whether its an eligible bar.
You do not have the required permissions to view the files attached to this post.
Bruce Flea
Trader
Posts: 18
Joined: Mon Feb 13, 2012 4:43 am

Re: Who wants a challenge?

Post by Bruce Flea »

Still not clear on how you propose to determine direction that gaheitman asked for clarification on as well.

Something like:

Code: Select all

if(High[1]<iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0) &&         High[0]>iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0)
would give you an up move notification as price didn't cross the previous bar, but did breach on the current bar. The reverse for a short.

And you have nothing that would currently indicate your program is looking to open a trade. In fact, it's still coded as an indicator.
fxprotrader
Trader
Posts: 26
Joined: Sat Jun 16, 2012 11:26 pm

Re: Who wants a challenge?

Post by fxprotrader »

Bruce Flea wrote:Still not clear on how you propose to determine direction that gaheitman asked for clarification on as well.

Something like:

Code: Select all

if(High[1]<iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0) &&         High[0]>iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0)
would give you an up move notification as price didn't cross the previous bar, but did breach on the current bar. The reverse for a short.

And you have nothing that would currently indicate your program is looking to open a trade. In fact, it's still coded as an indicator.
Determining direction is the easy part. I've got that all worked out.
If you take what I have in the screenshot using the M1 timeframe and start at August 02, 10:15 this will be a buy.

I have updated the code where it works fairly well up to about the 4th bar past the straddle, but this is way too inefficient, there's got to be a better way to do this. I've tried using a loop structure and again came very close to what I needed but in the end just was not correct. As I said it looks simple, but unless I'm missing something obvious it's not.

As far as it being coded as an indicator it is not, as I stated in the last post all I'm trying to determine at this point is which bars are eligible to execute a trade on, once I have that worked out then I'll put my code in to execute the trade. I'm marking the eligible bars with an arrow.

Code: Select all

//--------------------------------

double Poin;
//+------------------------------------------------------------------+
//| Custom initialization function                                    |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   if (Point==0.00001) Poin=0.0001;
   else {
      if (Point==0.001) Poin=0.01;
      else Poin=Point;
   }

//----
   return(0);
  }
//+------------------------------------------------------------------+
//                                                                   +
//+------------------------------------------------------------------+
int deinit(){
   

   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                           |
//+------------------------------------------------------------------+
int start(){

int MAM1StartBar=1;
int M1MAEntryPoint1=0;
int M1MAEntryPoint2=5;

string sObjName;

//------Indicators-------------//
double MAM0= iMA(NULL,0,20,0,0,0,MAM1StartBar);   
double MAM1= iMA(NULL,0,20,0,0,0,MAM1StartBar+1);   

 double M1High0  =  NormalizeDouble(iHigh(NULL,PERIOD_M1,MAM1StartBar),Digits);
 double M1High1  =  NormalizeDouble(iHigh(NULL,PERIOD_M1,MAM1StartBar+1),Digits);
 double M1High2  =  NormalizeDouble(iHigh(NULL,PERIOD_M1,MAM1StartBar+2),Digits);
 double M1High3  =  NormalizeDouble(iHigh(NULL,PERIOD_M1,MAM1StartBar+3),Digits);
 double M1High4  =  NormalizeDouble(iHigh(NULL,PERIOD_M1,MAM1StartBar+4),Digits);
 double M1High5  =  NormalizeDouble(iHigh(NULL,PERIOD_M1,MAM1StartBar+5),Digits);
 double M1Low0  =    NormalizeDouble(iLow(NULL,PERIOD_M1,MAM1StartBar),Digits);
 double M1Low1  =    NormalizeDouble(iLow(NULL,PERIOD_M1,MAM1StartBar+1),Digits);
 double M1Low2  =    NormalizeDouble(iLow(NULL,PERIOD_M1,MAM1StartBar+2),Digits);
 double M1Low3  =    NormalizeDouble(iLow(NULL,PERIOD_M1,MAM1StartBar+3),Digits);
 double M1Low4  =    NormalizeDouble(iLow(NULL,PERIOD_M1,MAM1StartBar+4),Digits);
 double M1Low5  =    NormalizeDouble(iLow(NULL,PERIOD_M1,MAM1StartBar+5),Digits);

double MAM1TRL1=NormalizeDouble(MAM0+M1MAEntryPoint1*Poin,Digits);
double MAM1TRL2=NormalizeDouble(MAM0+M1MAEntryPoint2*Poin,Digits);


//Blue arrow indicates straddle bar
if(M1High0>= MAM0 && M1Low0<=MAM0){
  sObjName="Test_BLine1"+Time[MAM1StartBar];
 ObjectCreate(sObjName, OBJ_ARROW, 0, Time[MAM1StartBar],Low[MAM1StartBar]-1.5*Poin);   
 ObjectSet(sObjName, OBJPROP_ARROWCODE, 241); 
 ObjectSet(sObjName, OBJPROP_COLOR, Blue);
}

//Aqua arrow indicates straddle bar+1
if(M1Low1<=MAM0 && M1High1>=MAM0){
if(M1High1<=MAM0+M1MAEntryPoint2*Poin){
if(M1Low0 > MAM0&& M1High1>=M1MAEntryPoint2*Poin){ 

sObjName="Test_BLine2"+Time[MAM1StartBar];
 ObjectCreate(sObjName, OBJ_ARROW, 0, Time[MAM1StartBar],Low[MAM1StartBar]-1*Poin);   
 ObjectSet(sObjName, OBJPROP_ARROWCODE, 241); 
 ObjectSet(sObjName, OBJPROP_COLOR, Aqua);

}
}
}

if(M1Low2<=MAM0 && M1High2>=MAM0){
if(M1High1<=MAM0+M1MAEntryPoint2*Poin){
if(M1High2<=MAM0+M1MAEntryPoint2*Poin){
if(M1Low0 > MAM0&& M1High1<=MAM0+M1MAEntryPoint2*Poin){

sObjName="Test_BLine3"+Time[MAM1StartBar];
 ObjectCreate(sObjName, OBJ_ARROW, 0, Time[MAM1StartBar],Low[MAM1StartBar]-2*Poin);   
 ObjectSet(sObjName, OBJPROP_ARROWCODE, 241); 
 ObjectSet(sObjName, OBJPROP_COLOR, Red);

}
}
}
}

if(M1Low3<=MAM0 && M1High3>=MAM0){
if(M1High1<=MAM0+M1MAEntryPoint2*Poin){
if(M1High2<=MAM0+M1MAEntryPoint2*Poin){
if(M1High3<=MAM0+M1MAEntryPoint2*Poin){
if(M1Low0 > MAM0 && M1High1<=MAM0+M1MAEntryPoint2*Poin){ 

sObjName="Test_BLine4"+Time[MAM1StartBar];
 ObjectCreate(sObjName, OBJ_ARROW, 0, Time[MAM1StartBar],Low[MAM1StartBar]-2.3*Poin);   
 ObjectSet(sObjName, OBJPROP_ARROWCODE, 241); 
 ObjectSet(sObjName, OBJPROP_COLOR, Gray);

}
}
}
}
}

if(M1Low4<=MAM0 && M1High4>=MAM0){
if(M1High1<=MAM0+M1MAEntryPoint2*Poin){
if(M1High2<=MAM0+M1MAEntryPoint2*Poin){
if(M1High3<=MAM0+M1MAEntryPoint2*Poin){
if(M1High4<=MAM0+M1MAEntryPoint2*Poin){
if(M1Low0 > MAM0 && M1High0<=MAM0+M1MAEntryPoint2*Poin){ 

sObjName="Test_BLine5"+Time[MAM1StartBar];
 ObjectCreate(sObjName, OBJ_ARROW, 0, Time[MAM1StartBar],Low[MAM1StartBar]-2.6*Poin);   
 ObjectSet(sObjName, OBJPROP_ARROWCODE, 241); 
 ObjectSet(sObjName, OBJPROP_COLOR, Sienna);

}
}
}
}
}
}


//----
   return(0);
  }
Bruce Flea
Trader
Posts: 18
Joined: Mon Feb 13, 2012 4:43 am

Re: Who wants a challenge?

Post by Bruce Flea »

I missed your reference to a higher time frame for direction.

Sorry 'bout that!

As for your conundrum, then as long as it was under that +5 pip limit, wouldn't the first bar that crosses just be your default? Especially since it fits your rules posted in the pic above.

And you're right. Telling it to wait, after it does get a valid signal will be difficult.

I'll be interested to see what comes of this.

Cheers!
Post Reply

Return to “Coders Hangout”