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

    • Be careful who you blame.   I can tell you one thing for sure.   Effective traders don’t blame others when things start to go wrong.   You can hang onto your tendency to play the victim, or the martyr… but if you want to achieve in trading, you have to be prepared to take responsibility.   People assign reasons to outcomes, whether based on internal or external factors.   When traders face losses, it's common for them to blame bad luck, poor advice, or other external factors, rather than reflecting on their own personal attributes like arrogance, fear, or greed.   This is a challenging lesson to grasp in your trading journey, but one that holds immense value.   This is called attribution theory. Taking responsibility for your actions is the key to improving your trading skills. Pause and ask yourself - What role did I play in my financial decisions?   After all, you were the one who listened to that source, and decided to act on that trade based on the rumour. Attributing results solely to external circumstances is what is known as having an ‘external locus of control’.   It's a concept coined by psychologist Julian Rotter in 1954. A trader with an external locus of control might say, "I made a profit because the markets are currently favourable."   Instead, strive to develop an "internal locus of control" and take ownership of your actions.   Assume that all trading results are within your realm of responsibility and actively seek ways to improve your own behaviour.   This is the fastest route to enhancing your trading abilities. A trader with an internal locus of control might proudly state, "My equity curve is rising because I am a disciplined trader who faithfully follows my trading plan." Author: Louise Bedford Source: https://www.tradinggame.com.au/
    • SELF IMPROVEMENT.   The whole self-help industry began when Dale Carnegie published How to Win Friends and Influence People in 1936. Then came other classics like Think And Grow Rich by Napoleon Hill, Awaken the Giant Within by Tony Robbins toward the end of the century.   Today, teaching people how to improve themselves is a business. A pure ruthless business where some people sell utter bullshit.   There are broke Instagrammers and YouTubers with literally no solid background teaching men how to be attractive to women, how to begin a start-up, how to become successful — most of these guys speaking nothing more than hollow motivational words and cliche stuff. They waste your time. Some of these people who present themselves as hugely successful also give talks and write books.   There are so many books on financial advice, self-improvement, love, etc and some people actually try to read them. They are a waste of time, mostly.   When you start reading a dozen books on finance you realize that they all say the same stuff.   You are not going to live forever in the learning phase. Don't procrastinate by reading bull-shit or the same good knowledge in 10 books. What we ought to do is choose wisely.   Yes. A good book can change your life, given you do what it asks you to do.   All the books I have named up to now are worthy of reading. Tim Ferriss, Simon Sinek, Robert Greene — these guys are worthy of reading. These guys teach what others don't. Their books are unique and actually, come from relevant and successful people.   When Richard Branson writes a book about entrepreneurship, go read it. Every line in that book is said by one of the greatest entrepreneurs of our time.   When a Chinese millionaire( he claims to be) Youtuber who releases a video titled “Why reading books keeps you broke” and a year later another one “My recommendation of books for grand success” you should be wise to tell him to jump from Victoria Falls.   These self-improvement gurus sell you delusions.   They say they have those little tricks that only they know that if you use, everything in your life will be perfect. Those little tricks. We are just “making of a to-do-list before sleeping” away from becoming the next Bill Gates.   There are no little tricks.   There is no success-mantra.   Self-improvement is a trap for 99% of the people. You can't do that unless you are very, very strong.   If you are looking for easy ways, you will only keep wasting your time forgetting that your time on this planet is limited, as alive humans that is.   Also, I feel that people who claim to read like a book a day or promote it are idiots. You retain nothing. When you do read a good book, you read slow, sometimes a whole paragraph, again and again, dwelling on it, trying to internalize its knowledge. You try to understand. You think. It takes time.   It's better to read a good book 10 times than 1000 stupid ones.   So be choosy. Read from the guys who actually know something, not some wannabe ‘influencers’.   Edit: Think And Grow Rich was written as a result of a project assigned to Napoleon Hill by Andrew Carnegie(the 2nd richest man in recent history). He was asked to study the most successful people on the planet and document which characteristics made them great. He did extensive work in studying hundreds of the most successful people of that time. The result was that little book.   Nowadays some people just study Instagram algorithms and think of themselves as a Dale Carnegie or Anthony Robbins. By Nupur Nishant, Quora Profits from free accurate cryptos signals: https://www.predictmag.com/    
    • there is no avoiding loses to be honest, its just how the market is. you win some and hopefully more, but u do lose some. 
    • $CSCO Cisco Systems stock, nice top of range breakout, from Stocks to Watch at https://stockconsultant.com/?CSCOSEPN Septerna stock watch for a bottom breakout, good upside price gap
    • $CSCO Cisco Systems stock, nice top of range breakout, from Stocks to Watch at https://stockconsultant.com/?CSCOSEPN Septerna stock watch for a bottom breakout, good upside price gap
×
×
  • Create New...

Important Information

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