NexusFi: Find Your Edge


Home Menu

 





Beginner EasyLanguage Question on Variables


Discussion in EasyLanguage Programming

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




 
Search this Thread

Beginner EasyLanguage Question on Variables

  #1 (permalink)
gurji
Miami, Florida
 
Posts: 35 since Apr 2022
Thanks Given: 1
Thanks Received: 10

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.

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
MC PL editor upgrade
MultiCharts
Better Renko Gaps
The Elite Circle
How to apply profiles
Traders Hideout
REcommedations for programming help
Sierra Chart
Exit Strategy
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Just another trading journal: PA, Wyckoff & Trends
25 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
23 thanks
GFIs1 1 DAX trade per day journal
17 thanks
  #2 (permalink)
gurji
Miami, Florida
 
Posts: 35 since Apr 2022
Thanks Given: 1
Thanks Received: 10

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);

Reply With Quote
  #3 (permalink)
 
syswizard's Avatar
 syswizard 
Philadelphia PA
 
Experience: Advanced
Platform: Multicharts
Broker: Ironbeam, Rithmic
Trading: Emini ES / NQ / CL / RTY / YM / BTC
Posts: 344 since Jan 2019
Thanks Given: 20
Thanks Received: 146


 
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.

Reply With Quote
  #4 (permalink)
gurji
Miami, Florida
 
Posts: 35 since Apr 2022
Thanks Given: 1
Thanks Received: 10

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 View Post
 
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.


Reply With Quote
  #5 (permalink)
gurji
Miami, Florida
 
Posts: 35 since Apr 2022
Thanks Given: 1
Thanks Received: 10

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.

Reply With Quote
  #6 (permalink)
gurji
Miami, Florida
 
Posts: 35 since Apr 2022
Thanks Given: 1
Thanks Received: 10

Hi, thanks! You solved the issue. Much clearer now.

Reply With Quote




Last Updated on September 8, 2022


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts