How to code? - page 320

 

Hi all, I would like to check if there is a way to track the current price?

E.g. when the price cross a pre-set point, it will immediate trigger a trade. The ones I found online are mainly referring to the close, high, low etc of the bar. Can someone please help me. Thanks.

Regards

Terrance

 

If I understand you correctly, you should use Askand Bid. Ask for a new buy order and bid for a new sell order

tkuan77:
Hi all, I would like to check if there is a way to track the current price?

E.g. when the price cross a pre-set point, it will immediate trigger a trade. The ones I found online are mainly referring to the close, high, low etc of the bar. Can someone please help me. Thanks.

Regards

Terrance
 

Yes Mladen, that is what I am using now. Maybe my question is not clearly explained. What I am trying to achieve is say example, I preset a point, example previous D1 candle close plus and minus 20pips, and if the current price hit the preset point of either (D1 + 20pips) or (D1 - 20pips), it will trigger either a buy or sell irregardless whether the current candle is it close or now.

So what I am trying to achieve now is how to make my system trigger the trade when the price hit the so call (D1 + 20pips) or (D1 - 20pips). Thanks in advance for the advice.

Regards

Terrance

mladen:
If I understand you correctly, you should use Askand Bid. Ask for a new buy order and bid for a new sell order
 

Now I am really nor sure if I understand but, will give it a try. Ty something like this (this is not a real code but just an example how to check - in most cases close and bid are the same)

if (close[1](D1+20pips)) trigger up action

if (close[1]>(D1-20pips) && close[0]<(D1-20pips)) trigger down action

tkuan77:
Yes Mladen, that is what I am using now. Maybe my question is not clearly explained. What I am trying to achieve is say example, I preset a point, example previous D1 candle close plus and minus 20pips, and if the current price hit the preset point of either (D1 + 20pips) or (D1 - 20pips), it will trigger either a buy or sell irregardless whether the current candle is it close or now.

So what I am trying to achieve now is how to make my system trigger the trade when the price hit the so call (D1 + 20pips) or (D1 - 20pips). Thanks in advance for the advice.

Regards

Terrance
 

Hi Mladen,

Yes, I have managed to solve quite a few of the errors that I have encountered, however 1 still bugs me. How do I trigger:

1) Long trade when FastMA1 crosses SlowMA1 by 10pips upwards

2) Short trade when FastMA1 crosses SlowMA1 by 10pips downwards

The thing that I do not know is how to add in the MA to react to the 10pips in the code.

/*--------------------------------------------------------------------------------*/

FastMA1 = iMA(NULL,PERIOD_M30,10,0,MODE_SMA,PRICE_CLOSE,0);

SlowMA1= iMA(NULL,PERIOD_M30,20,0,MODE_SMA,PRICE_CLOSE,1);

if(FastMA1 > SlowMA1)

{Long}

if(FastMA1 < SlowMA1)

{Short}

/*--------------------------------------------------------------------------------*/

Thanks and appreciate for the help.

Regards

Terrance

mladen:
Now I am really nor sure if I understand but, will give it a try. Ty something like this (this is not a real code but just an example how to check - in most cases close and bid are the same)
if (close[1](D1+20pips)) trigger up action

if (close[1]>(D1-20pips) && close[0]<(D1-20pips)) trigger down action

 

Try something like this :

double pipMultiplier=1; if (Digits==3 || Digits==5) pipMultiplier=10;

double diff = 10*Point*pipMultiplier;

if(FastMA1 > SlowMA1+diff)

{Long}

if(FastMA1 < SlowMA1-diff)

{Short}

tkuan77:
Hi Mladen,

Yes, I have managed to solve quite a few of the errors that I have encountered, however 1 still bugs me. How do I trigger:

1) Long trade when FastMA1 crosses SlowMA1 by 10pips upwards

2) Short trade when FastMA1 crosses SlowMA1 by 10pips downwards

The thing that I do not know is how to add in the MA to react to the 10pips in the code.

/*--------------------------------------------------------------------------------*/

FastMA1 = iMA(NULL,PERIOD_M30,10,0,MODE_SMA,PRICE_CLOSE,0);

SlowMA1= iMA(NULL,PERIOD_M30,20,0,MODE_SMA,PRICE_CLOSE,1);

if(FastMA1 > SlowMA1)

{Long}

if(FastMA1 < SlowMA1)

{Short}

/*--------------------------------------------------------------------------------*/

Thanks and appreciate for the help.

Regards

Terrance
 

Malden i try to code the indicator how your answer regarding the previous h1 candle day. But i could not do it.

I have an example.

I have an indicator with only one buffer in separate windows. It draw a line like rsi, atr etc etc.

Now i need to add a line (horizontal) in the same separate windows that is calculate from the average of the last 24 day indicator value (It is only for 1hour for this reasons i told 24). How i can do it? It is possible to draw this line for each day in the past?

I know that i must add another buffer.

How i can give at this buffer what i need?

Thank you

 

...

dasio

What you are describing looks like a combination of a regular indicator (the rsi, atr, ...) and a multi time frame average of that same indicator. Have you tried it that way?

dasio:
Malden i try to code the indicator how your answer regarding the previous h1 candle day. But i could not do it.

I have an example.

I have an indicator with only one buffer in separate windows. It draw a line like rsi, atr etc etc.

Now i need to add a line (horizontal) in the same separate windows that is calculate from the average of the last 24 day indicator value (It is only for 1hour for this reasons i told 24). How i can do it? It is possible to draw this line for each day in the past?

I know that i must add another buffer.

How i can give at this buffer what i need?

Thank you
 
mladen:
dasio What you are describing looks like a combination of a regular indicator (the rsi, atr, ...) and a multi time frame average of that same indicator. Have you tried it that way?

Hi, thank you for oyur reply,

Maybe I have not explained well.

I create an indicator that draw a line in a separate chart windows with my own calculation based on previous bars.

Now i need to add a line in the indicator where the value of this line is equal at the evarage of the last 24 value calculated in the last day and i need to draw this line in the previous day. I attached an image. However this line must be calculated at the end of the day cause it must be calculated for the la 24 value of the indicator for the same day where i calculate it.

For the moment this indicator must be used only in 1 hour timeframe so it isn't MTF indicator.

Thank you.

ps. White line are calculated for the same 24 value of the 1 day period where they are print.

Files:
example_1.gif  7 kb
 

...

dasio

Try something like this :

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_color1 OrangeRed

#property indicator_color2 Silver

#property indicator_width1 2

extern int RsiPeriod = 50;

extern int RsiPrice = PRICE_CLOSE;

double work[];

double avg[];

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

//

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

//

//

//

//

//

int init()

{

SetIndexBuffer(0,work);

SetIndexBuffer(1,avg);

return(0);

}

int start()

{

int i,countedBars = IndicatorCounted();

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

if (countedBars>0) countedBars--;

int limit = MathMin(Bars-countedBars,Bars-1);

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

{

work = iRSI(NULL,0,RsiPeriod,RsiPrice,i);

int y = iBarShift(NULL,PERIOD_D1,Time);

int x = iBarShift(NULL,PERIOD_D1,Time);

if (x!=y)

{

int k = iBarShift(NULL,0,iTime(NULL,PERIOD_D1,y));

double average = work[k];

int c = 1;

for (int j=k-1; j>=i; j--,c++) average += work[j]; average /= c;

for ( j=k ; j>=i; j--) avg[j] = average;

}

}

return(0);

}

dasio:
Hi, thank you for oyur reply,

Maybe I have not explained well.

I create an indicator that draw a line in a separate chart windows with my own calculation based on previous bars.

Now i need to add a line in the indicator where the value of this line is equal at the evarage of the last 24 value calculated in the last day and i need to draw this line in the previous day. I attached an image. However this line must be calculated at the end of the day cause it must be calculated for the la 24 value of the indicator for the same day where i calculate it.

For the moment this indicator must be used only in 1 hour timeframe so it isn't MTF indicator.

Thank you.

ps. White line are calculated for the same 24 value of the 1 day period where they are print.

Files:
test.gif  34 kb
Reason: