My newbie question about >= and >

Questions about MultiCharts and user contributed studies.
dunadan
Posts: 3
Joined: 06 Sep 2013
Has thanked: 3 times

My newbie question about >= and >

Postby dunadan » 22 Apr 2021

I have 2 newbie questions:

1. Working on my code, if I want to signal an order entry, (for example) if I wanted to trigger an order when the value for the 50-bar EMA is greater than the EMA_value was 1 bar ago, then I'm thinking that my code would be...
If EMA_value[0] > EMA_value[1] then.... (trigger Long entry, etc, etc).

But I don't want the signal to trigger an order entry if the value of the current bar's EMA_value is EQUAL TO (or "=") value of 1 bar ago. That is, I don't want the signal to trigger order entry if the EMA_value was 51.37 1 bar ago and if Multicharts shows the current bar EMA_value to equal that same 51.37.
But my problem is, I find is that the signal is being triggered anytime the value is > OR = the EMA_value from 1 bar ago. (So, not just when the value is > 1 bar ago.)

2. Another question, when I use ">=" such as signal if the current bar's EMA_value is greater than OR equal to the EMA_value from 1 bar ago, then my test results seems to be random about whether it triggers or not.
So, I'm guessing that ">=" does not work in Multicharts?

tpredictor
Posts: 108
Joined: 05 Mar 2014
Has thanked: 1 time
Been thanked: 12 times

Re: My newbie question about >= and >

Postby tpredictor » 22 Apr 2021

Something basic like this is very unlikely a bug in MC. Suggest you post code. It is likely error on your part.

dunadan
Posts: 3
Joined: 06 Sep 2013
Has thanked: 3 times

Re: My newbie question about >= and >

Postby dunadan » 22 Apr 2021

I don't know what's wrong with my entries.

Code: Select all

Inputs: EMA_Price ( Close ), EMA_Length (30 ); Variables: linRegValue ( 0 ), emaValue ( 0 ); if BarStatus( 1 ) = 2 then begin emaValue = XAverage( EMA_Price, EMA_Length ) ; end ; begin if emaValue[0] > emaValue[1] then Buy next bar market; end ;

dunadan
Posts: 3
Joined: 06 Sep 2013
Has thanked: 3 times

Re: My newbie question about >= and >

Postby dunadan » 22 Apr 2021

Actually, looking at my results again, I *think* what might be happenning is that what I see in the Data Window is a "rounded up" or rounded down number limited out to only 2 decimal places, while the signal is NOT rounding up or rounding down the number (even though the Data Window IS rounding the number out to 2 decimal places.

So when I see a reading of 51.37 for emaValue in the Data Window for BOTH this bar & 1 bar ago, the actual number (if NOT rounded up to 2 decimal places) might be 51.379947 and 51.376647. That might explain why the numbers look the same in the Data Window, but the code is treating one to be GreatThan ">" the other emaValue.

IF that's the case, then I need some way to "round up" to 2 decimal places the computed values inside my code, so that my code's emaValue is identical to the emaValue I see displayed by MC in the DataWindow when I move my mouse over any bar.

Is there a way to "round up" out to 2 decimal places in my code for any indicator value outputs? All I want is for whatever numbers I see displayed in MC's Data Window to be identical to the number that my code is using for its computations.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: My newbie question about >= and >

Postby TJ » 22 Apr 2021

Wiki
Go to 8 PowerLanguage Keyword Reference
Look under
Math and Trig‎ (29 P)

ROUND


Return to “MultiCharts”