stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

Basic coding question
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=2534
Page 1 of 1
Author:  traderuk [ Sun Jun 16, 2013 3:28 pm ]
Post subject:  Basic coding question

Hi,

I'm new at coding but I'm trying to learn. After a few hours still can't figure what I'm doing wrong, my brain won't work it out. Can you help please?

I'm trying to only place buy orders if the price is above EMA200 and only place sell if below EMA200... with some WPR in there too.

The thought being if price is above EMA on D1 and H1, then current chart which EA is attached will determine WRP entry points.

Many thanks!

Code: Select all

sig_high=iWPR(NULL,0,TrigWPR,1);
sig_low=iWPR(NULL,0,TrigWPR,1);
sig_iMA1=iMA(PERIOD_D1,0,200,0,MODE_EMA,PRICE_MEDIAN,0);
sig_iMA2=iMA(PERIOD_H1,0,200,0,MODE_EMA,PRICE_MEDIAN,0);

if (sig_iMA1>Close[1] && sig_iMA2>Close[1] /*&& sig_buy<TrigBuyStoch*/ && sig_high<TrigBuyWPR) {     
 BuyValue=1; 
}
 

if (sig_iMA1<Close[1] && sig_iMA2<Close[1] /*&& sig_sell>TrigSellStoch*/ && sig_low>TrigSellWPR) {     
 SellValue=1;
}
Author:  traderuk [ Sun Jun 16, 2013 3:42 pm ]
Post subject:  Re: Basic coding question

Shuffled the code around a bit and it seems to work... not sure why yet...

Code: Select all


      if (sig_iMA1<Close[1] && sig_iMA2<Close[1]) {
ticket=OrdSend(Symbol(),OP_SELL,Ilo,Bid,Slippage,MyStopLoss,MyTakeProfit,OrderStr,MagicNumber,0,Red);
      }

Author:  traderuk [ Wed Jun 19, 2013 2:59 pm ]
Post subject:  Re: Basic coding question

It turns out both methods worked just fine.
Author:  dietcoke [ Wed Jun 19, 2013 5:50 pm ]
Post subject:  Re: Basic coding question

traderuk wrote:Hi,

I'm new at coding but I'm trying to learn. After a few hours still can't figure what I'm doing wrong, my brain won't work it out. Can you help please?

I'm trying to only place buy orders if the price is above EMA200 and only place sell if below EMA200... with some WPR in there too.

The thought being if price is above EMA on D1 and H1, then current chart which EA is attached will determine WRP entry points.

Many thanks!

Code: Select all

sig_high=iWPR(NULL,0,TrigWPR,1);
sig_low=iWPR(NULL,0,TrigWPR,1);
sig_iMA1=iMA(PERIOD_D1,0,200,0,MODE_EMA,PRICE_MEDIAN,0);
sig_iMA2=iMA(PERIOD_H1,0,200,0,MODE_EMA,PRICE_MEDIAN,0);

if (sig_iMA1>Close[1] && sig_iMA2>Close[1] /*&& sig_buy<TrigBuyStoch*/ && sig_high<TrigBuyWPR) {     
 BuyValue=1; 
}
 

if (sig_iMA1<Close[1] && sig_iMA2<Close[1] /*&& sig_sell>TrigSellStoch*/ && sig_low>TrigSellWPR) {     
 SellValue=1;
}

Code: Select all

sig_iMA1>Close[1] && sig_iMA2>Close[1]

What you are saying there is buy if both MA's are higher than the price which does contradict your comments.
Author:  traderuk [ Mon Jun 24, 2013 4:53 pm ]
Post subject:  Re: Basic coding question

dietcoke wrote:

Code: Select all

sig_high=iWPR(NULL,0,TrigWPR,1);
sig_low=iWPR(NULL,0,TrigWPR,1);
sig_iMA1=iMA(PERIOD_D1,0,200,0,MODE_EMA,PRICE_MEDIAN,0);
sig_iMA2=iMA(PERIOD_H1,0,200,0,MODE_EMA,PRICE_MEDIAN,0);

if (sig_iMA1>Close[1] && sig_iMA2>Close[1] /*&& sig_buy<TrigBuyStoch*/ && sig_high<TrigBuyWPR) {     
 BuyValue=1; 
}
 

if (sig_iMA1<Close[1] && sig_iMA2<Close[1] /*&& sig_sell>TrigSellStoch*/ && sig_low>TrigSellWPR) {     
 SellValue=1;
}

Code: Select all

sig_iMA1>Close[1] && sig_iMA2>Close[1]

What you are saying there is buy if both MA's are higher than the price which does contradict your comments.
Thank you! The two snippets of code were at different times of my learning, second bit of code was the updated piece where it made sense :lol:
All times are UTC Page 1 of 1