Jump to content

Welcome to the new Traders Laboratory! Please bear with us as we finish the migration over the next few days. If you find any issues, want to leave feedback, get in touch with us, or offer suggestions please post to the Support forum here.

  • Welcome Guests

    Welcome. You are currently viewing the forum as a guest which does not give you access to all the great features at Traders Laboratory such as interacting with members, access to all forums, downloading attachments, and eligibility to win free giveaways. Registration is fast, simple and absolutely free. Create a FREE Traders Laboratory account here.

Sign in to follow this  
aaa

<> in AFL (AmiBroker)

Recommended Posts

Hi

 

Silly quick question

 

The = signe in AFL (AmiBroker) is

 

==

 

What is the difference sign ?

 

in EasyLanguage ;

 

if whatever <> H

 

In AFL ;

 

if whatever ????????? H

 

ThanX

Share this post


Link to post
Share on other sites

Hi Ochie

 

I'm learning AFL

 

U afraid me saying AFL = C !!!!

 

I didn't knew that !!

 

C is complicate !!!!

 

!= works

 

But I I have error 6

 

What do U think ?

 

DR     = 	0 ;
DS     = 	0 ; 
ODR  = 	0 ;
ODS  = 	0 ;
PDR = 	0 ;
PDS = 	0 ;

if DS != PDS )			
  ODS  = PDS ;

if  ( DR != High AND DR < PDR )  // Error 6 here
 ODR = PDR;

 

 

I don't understand that below =

 

Error 6. Condition in IF, WHILE, FOR statements has to be Numeric or Boolean type. You can not use array here, please use [] (array subscript operator) to access array elements

The if keyword executes statement1 if expression is true (nonzero); if else is present and expression is false (zero), it executes statement2. After executing statement1 or statement2, control passes to the next statement. Expression must be boolean ( True/False) type (so it CANNOT be ARRAY because there would be no way do decide whether to execute statement1 or not, if for example array was: [True,True,False,.....,False,True] )

 

if( expression )

statement1;

else

statement2;

 

EXAMPLE

 

if( Close > Open ) // WRONG

Color = colorGreen; //statement 1

else

Color = colorRed; //statement 2

 

Plot(Close,"Colored Price",Color,styleCandle);

 

The above example is wrong, as both Open and Close are arrays and such expression as Close > Open is also an ARRAY. The solution depends on the statement. It’s either possible to implement it on bar-by-bar basis, with use of FOR loop:

 

for( i = 0; i < BarCount; i++ )

{

if( Close[ i ] > Open[ i ] ) // CORRECT

Color[ i ] = colorGreen;

else

Color[ i ] = colorRed;

}

 

Plot( Close, "Colored Price", Color, styleCandle );

 

It is also possible in this case to use IIf( ) function:

 

Color = IIf( Close > Open, colorGreen, colorRed ); // ALSO CORRECT - working directly on arrays

Plot( Close, "Colored Price", Color, styleCandle );

Share this post


Link to post
Share on other sites

ThanX 4 the reference Guide in C

 

It's great !!!

 

AmiBroker has an Xcellent help

 

So

 

In AFL AND is AND

 

I took off the AND and my error 6 is still here

 

Grrrrrr

 

DR     = 	0 ;
DS     = 	0 ; 
ODR  = 	0 ;
ODS  = 	0 ;
PDR = 	0 ;
PDS = 	0 ;

if DS != PDS )			
  ODS  = PDS ;

if  ( DR != High )  // Error 6 here
 ODR = PDR;

Share this post


Link to post
Share on other sites

Thanks for the AND info. I did not know that!

 

I'm not near a compiler to test.

Don't you have a bracket missing here after the "if"

or just a typo?

if DS != PDS )

ODS = PDS ;

Share this post


Link to post
Share on other sites

In AFL coding it is essential to distinguish between a number and array. High is an array of all highs in the chart.

if operator works only for comparing numbers and returns also a number (boolean).

On the other hand, IIf operates with arrays and returns also an array. It is like running if operation for every array element.

 

ODR = IIf (DR != High, PDR, 0);

 

This line says:

Take every array element in DR array and compare it to adequate (i.e. with the same index) element of array of Highs. If the compared array elements are different (!=), then the adeqate element of ODR array (i.e. an element with the same index as the compared elements of DR and High arrays) shall be equal to an adegate element of PDR array. Else it will be zero.

Obviously ODR will be an array after this operation.

 

EDIT:

 

Just to show the difference, I will write how to use if operator to get the same result as the line above gives.

 

for (i = 0; i < barcount; i++)

{

if (DR != High)

ODR = PDR;

else

ODR = 0;

}

Edited by Head2k

Share this post


Link to post
Share on other sites

Hi Head2K

 

I must say that it is hard 2 understand even tho your Xplanation is Xcellent

 

But now I don't have any error

 

I should have wrote the entire formula because now I dono how to incorporate the second condition

 

The best is 2 write it in EasyLangage

 

 

 

if DR <> H AND DR < PDR then 
        if PDR <> 0 then 
 	DR = PDR ;

 

Is it correct translation in AFL ?

 

for (i = 0; i < barcount; i++)
{
if (DR[i] != High[i] and DR < PDR )
      if (PDR[i] != 0 )
          DR[i] = PDR[i];
else
DR[i] = 0;
}

 

 

PS I understand NOW how EL is easy....

Share this post


Link to post
Share on other sites
...

PS I understand NOW how EL is easy....

 

 

EasyLanguage is a Procedural Language...

 

it takes instructions one step at a time.

 

 

C is an conceptual Language...

 

it starts with an idea... and takes instructions in parallel.

 

 

 

C is a powerful tool for the conceptual thinker,

 

EasyLanguage is an easier tool for the logical thinker.

Edited by Tams

Share this post


Link to post
Share on other sites

my last question

 

EL

 

inputs:
Periods(	10 ;

variables :
DR( 	0 ),
Eb( 	0 ),
EV( 	0 );

// different computations of DR

EV = Extremes( H , Periods ,  1 , DR , EB ) ;

 

AFL

 

DR( 	0 );
Eb( 	0 );
EV( 	0 );

// different computations of DR

EV  = HHV( H, Period  ); // where to put DR ?

 

PS

I don't find any documentation in Extremes function in TS Help

Strange because it works

Share this post


Link to post
Share on other sites

Here it is

 

Extremes (Function)

Disclaimer

 

The Extremes function returns the extreme highest or lowest value over a range of bars and how many bars ago the extreme value occurred. There may be times when two or more bars have the exact same extreme highest or lowest value; when this happens the function identifies the most recent occurrence.

 

Syntax

Extremes(Price,Length,HiLo,oExtremeVal,oExtremeBar)

 

Returns (Integer)

The oExtremeVal and oExtremeBar output parameters return the extreme value and the number of bars ago it occurred. The Extremes function itself returns a value of 1.

 

Parameters

Name

Type

Description

 

Price

Numeric

Specifies which bar value (price, function, or formula) to compare for highest and lowest extremes.

 

Length

Numeric

Sets the number of bars to consider for extremes.

 

HiLo

Numeric

Sets whether the function will return the highest or lowest extreme value. 1=Highest, -1=Lowest.

 

oExtremeVal

Numeric

Outputs the highest or lowest extreme value found for the range of bars based on the HiLo setting.

 

oExtremeBar

Numeric

Outputs the number of bars ago the extreme value occurred.

 

 

Remarks

The input parameter Price can be a bar value such as Close, High, Low, Open, or Volume. It can also be any mathematical calculation such as: ( High + Low) / 2, or a numeric function such as RSI, Stochastic, or ADX.

 

See Multiple Output Function for more information on using output parameters to return values.

 

Example

Assigns to Value2 the highest High of the last 20 bars using the oExtremeVal output parameter, and assigns to Value3 the number of bars ago the highest High occurred using oExtremeBar output parameter. Value1 is assigned a value of 1:

 

vars: oExtremeVal(0), oExtremeBar(0);

 

Value1 = Extremes(High, 20, 1, oExtremeVal, oExtremeBar);

 

Value2 = oExtremeVal;

 

Value3 = oExtremeBar;

 

 

 

See Also

ExtremesFC, ExtremesArray, NthExtremes.

Share this post


Link to post
Share on other sites
Hi Head2K

 

I must say that it is hard 2 understand even tho your Xplanation is Xcellent

 

But now I don't have any error

 

I should have wrote the entire formula because now I dono how to incorporate the second condition

 

The best is 2 write it in EasyLangage

 

 

 

if DR <> H AND DR < PDR then 
        if PDR <> 0 then 
 	DR = PDR ;

 

Is it correct translation in AFL ?

 

for (i = 0; i < barcount; i++)
{
if (DR[i] != High[i] and DR < PDR )
      if (PDR[i] != 0 )
          DR[i] = PDR[i];
else
DR[i] = 0;
}

 

 

PS I understand NOW how EL is easy....

 

I don't know EL, I never used it. But your transcription into AFL seems OK. AFL is also easy, once you get the difference between arrays and nubmers. And i would recommend using preferably array functions, as they are usually faster than loop code.

 

As for the Extremes function, according to documentation you get 2 values from it.

1. The value of the extreme

2. Where the extreme occured

 

In AFL you need two functions for that.

HHV for the value and HHVBARS for the number of bars since the high occurred. LLV and LLVBARS for lows.

 

Browse AmiBroker Help -> AFL chapter -> Categorized list of AFL functions -> Lowest/Highest

Share this post


Link to post
Share on other sites

What I've learned here in AFL

 

<> is !=

 

if is used only for nbers

OHLC are arrays not numbers

 

EL

if DR <> H AND DR < PDR then

DR = PDR ;

 

AFL

DR=IIf (DR != High AND DR < PDR, PDR, 0);

 

DR = PDR if condition is true else 0

 

and the result is now an array

 

Loops are slower

 

EL is logical

AFL is conceptual and need // instructions

 

Sometimes we need 2 functions in AFL to convert an EL function

Share this post


Link to post
Share on other sites

How 2 put the second condition if PDR <> 0 inside the formula ?

 

Target in EL

 

if DR <> H AND DR < PDR then

if PDR <> 0 then

DR = PDR ;

 

------------------------

 

First condition

 

if DR <> H AND DR < PDR then DR = PDR ;

 

DR=IIf (DR != High AND DR < PDR, PDR, 0);

 

 

Second Condition

 

if PDR <> 0 then DR = PDR ;

 

DR=IIf (PDR != High, PDR, 0);

Share this post


Link to post
Share on other sites

EV = Extremes( H , Periods , 1 , DR , EB ) ;

 

highest closing price = HHV( H, Period );

The formula "hhv( High, 4)" returns the highest closing price over the preceding four periods;

 

number of periods = HHVBARS( H, DR );

The formula "hhvbars( High, 4 )" returns the number of periods that have passed since the highest price reached its 4-period peak.

 

How to match HHV and HHVBARS to make EV ?

Share this post


Link to post
Share on other sites

My indicator has 537 lines code in EL

 

I've succeded to transpose in AFL all of them except the 2 problems above that I replace with something different

 

So I'm able To see the result on a chart

 

Is there a debug window with a print statment like in MC in AmiBroker ?

Share this post


Link to post
Share on other sites
How 2 put the second condition if PDR <> 0 inside the formula ?

 

Target in EL

 

if DR <> H AND DR < PDR then

if PDR <> 0 then

DR = PDR ;

 

------------------------

 

First condition

 

if DR <> H AND DR < PDR then DR = PDR ;

 

DR=IIf (DR != High AND DR < PDR, PDR, 0);

 

 

Second Condition

 

if PDR <> 0 then DR = PDR ;

 

DR=IIf (PDR != High, PDR, 0);

 

The exact transcription of your EL code would be

DR = IIf (PDR != High AND DR < PDR, IIf ( PDR != 0, PDR, 0), 0 );

That is one IIf function inside another one.

 

The only difference is that in IIf function "else" must be defined and I set DR to zero in "else" case. In another words, I believe your EL code doesn't say what DR is if the conditions aren't met. In this AFL code it says that DR will be set to zero then.

 

Anyway, I guess the code would be more efficient like this:

EL:

if DR <> H AND DR < PDR AND PDR <> 0 then

DR = PDR ;

 

AFL:

DR=IIf (PDR != High AND DR < PDR AND PDR != 0, PDR, 0);

 

In another words, you can put all the expressions into one condition.

 

Now to your previous post and array functions vs. loops.

I think in most cases you won't recognize the difference in speed. So if you happen to understand loops better than array functions, you can of course use loops.

Share this post


Link to post
Share on other sites
Anyway, I guess the code would be more efficient like this

 

Gooood

 

I've changed my code in EL

For the multiple steps of logical B4 the formula I've used 2 conditions 2 clear my mind and I didn't cleaned up this unusefull 2nd condition at the end of the proccess

 

I prefer the difficult way rather than the loop Bcoz it's more logical & elegant & short

 

This construction below is perfect 4 me

 

DR=

IIf (

PDR != High AND

DR < PDR AND

PDR != 0,

PDR,

0);

 

 

I'm very closed 2 my aims with your wonderfull help

 

Do you have any idea for the last problem ?

 

EV = Extremes( H , Periods , 1 , DR , EB ) ;

 

highest closing price = HHV( H, Period );

The formula "hhv( High, 4)" returns the highest closing price over the preceding four periods;

 

number of periods = HHVBARS( H, DR );

The formula "hhvbars( High, 4 )" returns the number of periods that have passed since the highest price reached its 4-period peak.

 

How to match HHV and HHVBARS to make EV ?

Share this post


Link to post
Share on other sites
Do you have any idea for the last problem ?

 

EV = Extremes( H , Periods , 1 , DR , EB ) ;

 

highest closing price = HHV( H, Period );

The formula "hhv( High, 4)" returns the highest closing price over the preceding four periods;

 

number of periods = HHVBARS( H, DR );

The formula "hhvbars( High, 4 )" returns the number of periods that have passed since the highest price reached its 4-period peak.

 

How to match HHV and HHVBARS to make EV ?

 

Well, that is more difficult for me because I don't know EL. But according to info you posted above

 

The Extremes function returns the extreme highest or lowest value over a range of bars and how many bars ago the extreme value occurred. There may be times when two or more bars have the exact same extreme highest or lowest value; when this happens the function identifies the most recent occurrence.

 

Syntax

Extremes(Price,Length,HiL o,oExtremeVal,oExtremeBar )

 

HHV returns oExtremeVal of Price in Length periods with HiLo set to 1.

LLV returns oExtremeVal of Price in Length periods with HiLo set to -1.

HHVBARS and LLVBARS return oExtremeBar, I believe. Because oExtremeBar outputs the number of bars ago the extreme value occurred and HHVBARS and LLVBARS outputs how many bars occurred since the extreme was reached, which is the same.

 

Just notice that HHV, LLV, HHVBARS and LLVBARS functions return arrays.

 

So your line

EV = Extremes( H , Periods , 1 , DR , EB ) ;

 

would be in AFL as follows:

 

DR = HHV ( H, Periods );

EB = HHVBARS ( H, Periods );

Share this post


Link to post
Share on other sites

DR = HHV ( H, Periods );

 

I've tried that B4 W/o success

 

We don't need EB

 

oExtremeBar

Numeric

Outputs the number of bars ago the extreme value occurred.

 

 

Here is my script at this point but I'm overlimit and I don't understang anything more

 

The algorythm is dancing the samba in my head

 

I wish 2 B more intelligent sometimes...

 

if ( DR != PDR )

ODR = PDR ;

 

ODR = PDR ;

 

PDR = DR ;

 

//oExtremeVal = Extremes( H , Periods , 1 , DR , oExtremeBar ) ;

 

DR =

IIf ( Dynamic_R != High AND Dynamic_R < PrevDynamic_R AND PrevDynamic_R != 0,

PrevDynamic_R, 0 );

Edited by aaa

Share this post


Link to post
Share on other sites

I guess I am missing the point here.

 

DR = HHV ( H, Periods );

generates an array called DR which, for every bar (= array element), contains the highest high in "periods" bars before and including that bar.

 

Then you take that DR array and redefine (=rewrite) it as follows

 

DR = IIf ( PDR != High AND DR < PDR AND PDR != 0, PDR, 0 );

 

The DR array used inside the IIf condition is the original DR array defined by the HHV function. But by the IIf function you then re-write it and assign either PDR or 0 to its elements depending on the condition.

 

That's what this code does. But perhaps it is not what you want it to do.

Share this post


Link to post
Share on other sites

You are so kind Head2K

 

I don't want 2 waist your time anymore

 

I will take time now 2 understand everything new I've learned

 

Array is a complicate concept 4 me

 

I need 2 find a new brain.

 

Is there cheap second hand brain with math option 2 buy on this site ?

 

I've started with AB & AFL one week ago

 

so I'm a real baby impatient 2 play with my new Xmas gift

 

if U don't mind, may B next WE I'll ask U some more help ?

 

Many thanX 4 your patience

 

And good sunday

 

aaa

Edited by aaa

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Topics

  • Posts

    • AXON Enterprise stock, top of range breakout at https://stockconsultant.com/?AXON
    • FOUR Shift4 Payments stock with a solid breakout above 122.9, from Stocks to Watch at https://stockconsultant.com/?FOUR
    • EBS Emergent Biosolutions stock watch, pullback to 9.9 triple+ support area with bullish indicators at https://stockconsultant.com/?EBS
    • POAI Predictive Oncology stock with a bull flag breakout, target 2 area at https://stockconsultant.com/?POAI
    • Date: 18th February 2025.   UK Unemployment Rate Falls and The Pound Spikes Upwards.     The British Pound spikes upwards against all currencies as the UK releases its employment data. However, the latest employment data release does not give long-term confidence as the UK continues to see a higher possibility of economic stagnation in 2025. Can the GBP maintain momentum?   UK Releases Latest Employment Data! The UK employment data had its positive and negative points. The Monthly Unemployment Claims rose 22,000 which is at a 3 month high, and higher than analysts’ previous expectations. This is known to be negative for the British Pound. However, the UK also saw some positive data which investors are clinging onto. The UK Unemployment Rate fell for the first time since October 2024. The UK Unemployment Rate, to the surprise of analysts, fell from 4.5% to 4.4%. Lastly, the Average UK Salaries Index rose to 6.00%, the highest in 13 months and higher than previous expectations. This is the main reason why the GBP is increasing in value. That said, the Bank of England and economists continue to expect the UK to witness stagnation in 2025.     The British Pound The British Pound is now one of the best-performing currencies of the day so far. The US Dollar and Japanese Yen are also strongly increasing in value. The Governor of the Bank of England, Mr Bailey, is due to speak at 09:30 GMT and is likely to comment on the latest employment data.   Previously, Bailey described the UK’s economic growth as “static,” despite stronger-than-expected Q4 2024 data—0.1% growth instead of the forecasted –0.1% quarterly and 1.4% annually versus the expected 1.1%. Meanwhile, the BoE revised its 2025 GDP growth forecast down to 0.75% from 1.0% in November. Traders are also hoping Governor Bailey will comment on the possible future rate cuts.   Tomorrow at 09:00 (GMT+2), the UK will release January inflation data. Analysts expect the annual CPI to rise from 2.5% to 2.8%, while monthly prices may drop by 0.3% after a similar increase in December. The Core CPI is projected to climb from 3.2% to 3.6%.   When evaluating the GBP Index, the GBP is currently trading 0.95% higher in 2025. However, the upward price movement is largely due to last week’s Gross Domestic Product which beat expectations. The performance of the GBP will also depend on whether the US imposes tariffs. Additionally, pressure on the UK to increase defence spending could further strain the country's already scrutinized budget.   GBPUSD - Technical Analysis and Price Condition The GBPUSD is trading above the main moving averages on the 2-hour timeframe and is trading high on most oscillators. These factors indicate that the buyers are currently controlling momentum, but traders are concerned about two factors. The first is that the GBPUSD is struggling to break above the 1.26300 level and the fact that both the USD and GBP is simultaneously increasing in value. As both currencies are increasing in value, technical analysts view the price action as conflicting. On the 5-minute chart, the GBPUSD is trading at the 200-bar average price movement indicating a neutral signal. This also follows the concerns of traders that the price action is conflicting.     If the price breaks above 1.25918, the GBPUSD may witness sell signals materialize. However, if the price breaks above 1.26200, buy signals may arise which will also be in line with the indications on the 2-hour timeframe.   Key Takeaway Points: GBP rises as the UK employment data lifts GBP, but stagnation concerns remain. UK Salaries hit a 13-month high, boosting the Pound. The Bank of England Governor, Mr Bailey may hint at future rate cuts and advises the UK will witness economic stagnation. The key risks for the GBP remain inflation data, US tariffs, and UK defence spending pressure. Always trade with strict risk management. Your capital is the single most important aspect of your trading business.   Please note that times displayed based on local time zone and are from time of writing this report.   Click HERE to access the full HFM Economic calendar.   Want to learn to trade and analyse the markets? Join our webinars and get analysis and trading ideas combined with better understanding of how markets work. Click HERE to register for FREE!   Click HERE to READ more Market news.   Michalis Efthymiou HFMarkets   Disclaimer: This material is provided as a general marketing communication for information purposes only and does not constitute an independent investment research. Nothing in this communication contains, or should be considered as containing, an investment advice or an investment recommendation or a solicitation for the purpose of buying or selling of any financial instrument. All information provided is gathered from reputable sources and any information containing an indication of past performance is not a guarantee or reliable indicator of future performance. Users acknowledge that any investment in Leveraged Products is characterized by a certain degree of uncertainty and that any investment of this nature involves a high level of risk for which the users are solely responsible and liable. We assume no liability for any loss arising from any investment made based on the information provided in this communication. This communication must not be reproduced or further distributed without our prior written permission.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.