Basic coding question

Post Reply
User avatar
traderuk
Trader
Posts: 18
Joined: Wed Mar 20, 2013 11:12 pm

Basic coding question

Post by traderuk »

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;
}
User avatar
traderuk
Trader
Posts: 18
Joined: Wed Mar 20, 2013 11:12 pm

Re: Basic coding question

Post by traderuk »

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);
      }

User avatar
traderuk
Trader
Posts: 18
Joined: Wed Mar 20, 2013 11:12 pm

Re: Basic coding question

Post by traderuk »

It turns out both methods worked just fine.
dietcoke
Trader
Posts: 162
Joined: Tue Nov 15, 2011 9:59 pm

Re: Basic coding question

Post by dietcoke »

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.
Image
User avatar
traderuk
Trader
Posts: 18
Joined: Wed Mar 20, 2013 11:12 pm

Re: Basic coding question

Post by traderuk »

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:
Post Reply

Return to “Coders Hangout”