Beginner EasyLanguage Question on Variables - futures io

# Discussion in EasyLanguage Programming

Updated
1. trending_up 2,111 views
2. thumb_up 0 thanks given
3. group 2 followers
1. forum 5 posts
2. attach_file 0 attachments

 Welcome to futures io: the largest futures trading community on the planet, with well over 150,000 members
 Genuine reviews from real traders, not fake reviews from stealth vendors Quality education from leading professional traders We are a friendly, helpful, and positive community We do not tolerate rude behavior, trolling, or vendors advertising in posts We are here to help, just let us know what you need You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple. -- Big Mike, Site Administrator (If you already have an account, login at the top of the page)

# Beginner EasyLanguage Question on Variables

gurji
Miami, Florida

Posts: 29 since Apr 2022

Hi, I just started messing around with EasyLanguage. I am just trying to put a small test strategy together for myself just to teach myself how this all works.
So in this example, I am trying to make my target exit price a percentage of the High/Low of the trigger bar.

I created a variables called HLSize which is just high-low, and then I multiply that by 0.25 in order to get 25% of the H/L. But just to make this easier for testing, let's just use the high-low as the amount without multiplying by a percent.

The problem is that it keeps recalculating the high low on every bar and the variable keeps updating. How do I store the high-low value of the trigger bar in a variable, or how do I at least set it as my take profit without it changing on every bar.

Here is my code:
(Note, I removed some stuff just to simplify it for this post, so some of the entry conditions might not make sense.)

Code
 ```vars: hlsize(0), ocsize(0), ocatr(0), slamt(0), tgamt(0),aaa(""); ocsize = absvalue(Open-Close); hlsize = (high-low); slamt = 500; if (value1 >= value3) and (close < open) and (ocatr <= 1.7) and (ocsize > 0.12) and (ocsize <= 0.35) then tgamt = hlsize; Buy this bar at close; SetStopLoss(slamt); SetProfitTarget(tgamt); if (value1 >= value3) and (open < close) and (ocatr <= 1.7) and (ocsize > 0.12) and (ocsize <= 0.35) then tgamt = hlsize; Sellshort this bar at close; SetStopLoss(slamt); SetProfitTarget(tgamt)```
Any help is appreciated.

Can you help answer these questions
from other members on futures io?
 Market on Close data within IBPlatforms and Indicators in depth understanding of last, bid, and ask volume in c …NinjaTrader Book for fundamental analysisStocks and ETFs Multi Time Frame High/Low/Median levelsNinjaTrader NT8 Order Management StrategyThe Elite Circle

in the last 7 days on futures io
 Is anyone actually making money?52 thanks An embarrassing, honest confession37 thanks Sierra vs. Ninja : why I chose .....8 thanks Machine Learning Journal5 thanks Institutional Grade Massive Data Dump for Quant Research …5 thanks

gurji
Miami, Florida

Posts: 29 since Apr 2022

Ok, I found a solution, but from a logical standpoint, I don't understand why it should be this way.

Immediately above the 2 IF statements, I put another IF statement with the same criteria, except without the test for the entry direction. Inside there, I put the tgamt=hlsize.
This works, but I'm still curious as to why I should have to do it this way. putting the tgamt=hlsize should do the same thing if I put it in the 2 IF staements.

What am I missing here?

Code
 ```if (value1 >= value3) and (ocatr <= 1.7) and (ocsize > 0.12) and (ocsize <= 0.35) then tgamt = hlsize; if (value1 >= value3) and (close < open) and (ocatr <= 1.7) and (ocsize > 0.12) and (ocsize <= 0.35) then Buy this bar at close; SetStopLoss(slamt); SetProfitTarget(tgamt); if (value1 >= value3) and (open < close) and (ocatr <= 1.7) and (ocsize > 0.12) and (ocsize <= 0.35) then Sellshort this bar at close; SetStopLoss(slamt); SetProfitTarget(tgamt);```

syswizard

Platform: Multicharts
Broker: Ironbeam, Rithmic
Trading: Emini ES / NQ / CL / RTY / YM / BTC

Posts: 344 since Jan 2019

Code
 ```vars: hlsize(0), ocsize(0), ocatr(0), slamt(0), tgamt(0),aaa(""); ocsize = absvalue(Open-Close); hlsize = (high-low); slamt = 500; if (value1 >= value3) and (close < open) and (ocatr <= 1.7) and (ocsize > 0.12) and (ocsize <= 0.35) then Begin tgamt = hlsize; Buy this bar at close; End; if (value1 >= value3) and (open < close) and (ocatr <= 1.7) and (ocsize > 0.12) and (ocsize <= 0.35) then Begin tgamt = hlsize; Sellshort this bar at close; End; If MarketPosition <> 0 Then Begin SetStopLoss(slamt); SetProfitTarget(tgamt*BigPointValue); End;```
tgamt should remain persistent....be sure you are not setting it back to zero.

gurji
Miami, Florida

Posts: 29 since Apr 2022

Hi, thanks for the help.
It was getting set to 0, but that was in the initial declaration of my variables. The way I understand this, is that TS basically runs the script once per bar. So I guess my issue is that i need a way to store a value without it being reset on each instance the script is run. I thought that I did it in the correct way by storing it in tgamt only when orders are placed. But that didn't work until I gave it another IF statement, which was essentially the same IF statement used to test entry conditions.
I think the BEGIN/END was the issue.

Then my next question stems from the BEGIN/END that you added. I looked those up, and I understand what they do, however, why did you remove the stoploss from them and move to a different condition?

Thanks again for you help!

syswizard

Code
 ```vars: hlsize(0), ocsize(0), ocatr(0), slamt(0), tgamt(0),aaa(""); ocsize = absvalue(Open-Close); hlsize = (high-low); slamt = 500; if (value1 >= value3) and (close < open) and (ocatr <= 1.7) and (ocsize > 0.12) and (ocsize <= 0.35) then Begin tgamt = hlsize; Buy this bar at close; End; if (value1 >= value3) and (open < close) and (ocatr <= 1.7) and (ocsize > 0.12) and (ocsize <= 0.35) then Begin tgamt = hlsize; Sellshort this bar at close; End; If MarketPosition <> 0 Then Begin SetStopLoss(slamt); SetProfitTarget(tgamt*BigPointValue); End;```
tgamt should remain persistent....be sure you are not setting it back to zero.

 (login for full post details) #5 (permalink) gurji Miami, Florida     Posts: 29 since Apr 2022 Thanks: 1 given, 8 received Ok, I realized just now that you also move the profit to the final IF statement too. I think I get it all now. I will post an update shortly.

 (login for full post details) #6 (permalink) gurji Miami, Florida     Posts: 29 since Apr 2022 Thanks: 1 given, 8 received Hi, thanks! You solved the issue. Much clearer now.

 futures io > Beginner EasyLanguage Question on Variables

Last Updated on September 8, 2022

Upcoming Webinars and Events