Coding a simple entry and exit - futures io
futures io futures trading



Coding a simple entry and exit


Discussion in EasyLanguage Programming

Updated by Jura
      Top Posters
    1. looks_one johni with 4 posts (0 thanks)
    2. looks_two RM99 with 3 posts (2 thanks)
    3. looks_3 Jura with 3 posts (3 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 11,559 views
    2. thumb_up 5 thanks given
    3. group 2 followers
    1. forum 10 replies
    2. attach_file 0 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 100,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)

 
Thread Tools Search this Thread
 

Coding a simple entry and exit

  #1 (permalink)
canada
 
 
Posts: 29 since Jun 2011
Thanks: 0 given, 0 received

Coding a simple entry and exit

Entry : Pattern 1 setup
Entry at highest high for buy and lowest low for sell
Must be filled within 2 to 3 bars

Exit : 1) Profit target calculated using the entry setup highest high - lowest low add to the highest high for buy or subtract from the lowest low for sell
2) Or exit on the lowest low for buy and highest high for sell

How to code the above?

Reply With Quote

Can you help answer these questions
from other members on futures io?
Convert NinjaTrader NT7 indicator to Tradestation EasyLanguage and RADARSCREEN
Platforms and Indicators
Issue meeting order entry conditions
Elite Automated NinjaTrader Trading
Last 5 minutes Label
ThinkOrSwim
Moving average with Lag reduction
NinjaTrader
Linux?
ThinkOrSwim
 
Best Threads (Most Thanked)
in the last 7 days on futures io
Spoo-nalysis ES e-mini futures S&P 500
62 thanks
June Charity Fundraiser - Feeding hungry families
50 thanks
FIO Journal Challenge - June 2020 edition w/SharkIndicators
40 thanks
Fixed vs trailing stops
30 thanks
AMP Futures / AMP Global Review
26 thanks
 
  #3 (permalink)
The Netherlands
 
Experience: None
Platform: MultiCharts, TradingView
Trading: ...
 
Jura's Avatar
 
Posts: 774 since Apr 2010
Thanks: 2,347 given, 685 received



johni View Post
Entry : Pattern 1 setup
Entry at highest high for buy and lowest low for sell
Must be filled within 2 to 3 bars

Exit : 1) Profit target calculated using the entry setup highest high - lowest low add to the highest high for buy or subtract from the lowest low for sell
2) Or exit on the lowest low for buy and highest high for sell

How to code the above?

On the top of my head, not compiled but it should get you started:
 
Code
                            
Vars:
    
myEntrySetupLong(false),
    
myEntrySetupShort(false),
    
barNumber(0),
    
limitPrice(0),
    
profitTarget(0),
    
exitPrice(0);
    
// Enter long setup
if ....pattern1.... then begin
    myEntrySetupLong 
true;
    
barNumber CurrentBar;            // store bar number
end else
    
myEnterSetupLong false;

// Enter short setup
if ....pattern1.... then begin
    myEntrySetupShort 
true;
    
barNumber CurrentBar;            // store bar number
end else
    
myEnterSetupShort false;
    
condition2 = (CurrentBar barNumber) < 4;            // enter within 4 bars

// Enter Long
if myEntrySetupLong true and condition2 true then begin
    limitPrice 
Highest(High10);                    // note: dynamic limit price!
    
exitPrice Lowest(Low10);
    
profitTarget limitPrice exitPrice;
    
Buy("EnterLong"1 contracts next bar at limitPrice limit;
end;

// Enter short
if myEntrySetupShort true and condition2 true then begin
    limitPrice 
Lowest(Low10);                    // note: dynamic limit price!
    
exitPrice Highest(High10);
    
profitTarget limitPrice exitPrice;
    
SellShort("EnterShort"1 contracts next bar at limitPrice limit;
end;

// Exit conditions for long
if MarketPosition 1 then begin
    Sell
("ExitLong"next bar at exitPrice stop;
    
Sell("TakeProfit"next bar at profitTarget limit;
end;

// Exit conditions for short
if MarketPosition = -1 then begin
    BuyToCover
("ExitShort"next bar at exitPrice stop;
    
BuyToCover("TakeProfit"next bar at profitTarget limit;
end
You need to check this code for yourself - I find your point 1 not very clear so I don't know if it's coded correctly.

Regards,

Reply With Quote
The following 2 users say Thank You to Jura for this post:
 
  #4 (permalink)
Austin, TX
 
Experience: Advanced
Platform: TradeStation
Trading: Futures
 
Posts: 882 since Mar 2011
Thanks: 124 given, 698 received


johni View Post
Entry : Pattern 1 setup
Entry at highest high for buy and lowest low for sell
Must be filled within 2 to 3 bars

Exit : 1) Profit target calculated using the entry setup highest high - lowest low add to the highest high for buy or subtract from the lowest low for sell
2) Or exit on the lowest low for buy and highest high for sell

How to code the above?

He did a decent job above, but he's right. You're rules have logic "challenges." Spotting the Highest H and the Lowest L is only possible in retrospect, even if you set a time interval, you don't know it's the highest high until after it's come and gone. (same with LL).

I guess if you're interval holds (2-3 bars) you would seek 3 consecutive HH's and enter a long position or 3 consecutive lower lows and enter a short position.

Again, for your exits, you cannot declare "Highest" or "Lowest" in real time...only in retrospect. You can evaluate a 10 bar period, but again, if for instance, you have a spike on bar #3, how do you know that was the highest high? You simply know it's higher, you cannot enter or exit based on "est."

On a side note, even if you could, wouldn't you want to sell at the high"est" point and buy at the low"est" point?

Reply With Quote
The following user says Thank You to RM99 for this post:
 
  #5 (permalink)
canada
 
 
Posts: 29 since Jun 2011
Thanks: 0 given, 0 received

The code uses dynamic price for the exits and profit targets but the pattern uses a fix profit target and exit

The pattern requires H>H[1] and indicator 1 crosses 0 and next bar open < H

Once satisfied place a buy order on the current bar high

Once filled, calculate the profit target using current bar H-L, not dynamic, add to the H for the profit target

The exit price is the current bar low

The trade once filled would either profit or exit on the current bar low using fix profit target, H-L, add to H or exit on the current bar low

Both the exit using orders place on the profit target calculated or the current bar low and the code should not use next bar exit

Currently using ts2000i

Reply With Quote
 
  #6 (permalink)
The Netherlands
 
Experience: None
Platform: MultiCharts, TradingView
Trading: ...
 
Jura's Avatar
 
Posts: 774 since Apr 2010
Thanks: 2,347 given, 685 received

Can you show us your code with which you tried to tackle this problem? Then we can build on that going forward. An image would also be helpful.

Reply With Quote
 
  #7 (permalink)
canada
 
 
Posts: 29 since Jun 2011
Thanks: 0 given, 0 received

Hi Jura,

Did not have any code because the pattern is derived browsing and considering there may be an advantage

The trade is simple a pattern with a fix profit target calculated using the current bar high and low and a exit on the current bar low but only the high must be more compare to preivous high

Your code is correct except for the dynamic profit target and exit

Would you change the code to a fix proft target and exit using the current bar high and low?

Tks

Reply With Quote
 
  #8 (permalink)
Austin, TX
 
Experience: Advanced
Platform: TradeStation
Trading: Futures
 
Posts: 882 since Mar 2011
Thanks: 124 given, 698 received


johni View Post
Hi Jura,

Did not have any code because the pattern is derived browsing and considering there may be an advantage

The trade is simple a pattern with a fix profit target calculated using the current bar high and low and a exit on the current bar low but only the high must be more compare to preivous high

Your code is correct except for the dynamic profit target and exit

Would you change the code to a fix proft target and exit using the current bar high and low?

Tks

That's what I was trying to tell you, you cannot determine the current bar's high/low until it's historical (in the past).

If your exit is based on this bar close, it may or may not be at the high/low. If you set the exit on the open of the next bar, again, it may or may not be at this bar's high low.

If you set the exit to run intrabar, every tick is evaluated and so if a bar opens at 100.00 and moves up to 100.01, then that is the current "high" and would trigger an exit.

Reply With Quote
 
  #9 (permalink)
canada
 
 
Posts: 29 since Jun 2011
Thanks: 0 given, 0 received


RM99 View Post
That's what I was trying to tell you, you cannot determine the current bar's high/low until it's historical (in the past).

If your exit is based on this bar close, it may or may not be at the high/low. If you set the exit on the open of the next bar, again, it may or may not be at this bar's high low.

If you set the exit to run intrabar, every tick is evaluated and so if a bar opens at 100.00 and moves up to 100.01, then that is the current "high" and would trigger an exit.

There is a misunderstanding

Understand what you are explaining

But the pattern is a historical pattern and the high and low are determined and orders are placed on these levels

Indicator 1 cross 0 and the bar high > previous bar high and next bar open < bar high place a buy order on the bar high
THE BAR HIGH IS DETERMINED BECAUSE THE NEXT BAR OPEN IS THE CURRENT BAR
No order is placed with next bar open > bar high must be < bar high

Should not say current bar high but rather previous bar high for order placement

Sell is the opposite

Reply With Quote
 
  #10 (permalink)
Austin, TX
 
Experience: Advanced
Platform: TradeStation
Trading: Futures
 
Posts: 882 since Mar 2011
Thanks: 124 given, 698 received



johni View Post
There is a misunderstanding

Understand what you are explaining

But the pattern is a historical pattern and the high and low are determined and orders are placed on these levels

Indicator 1 cross 0 and the bar high > previous bar high and next bar open < bar high place a buy order on the bar high
THE BAR HIGH IS DETERMINED BECAUSE THE NEXT BAR OPEN IS THE CURRENT BAR
No order is placed with next bar open > bar high must be < bar high

Should not say current bar high but rather previous bar high for order placement

Sell is the opposite

////////////////////////////////////////////////////////////////////////////////////////////
Variables: Indicatorx(0);

if marketposition = 0 then begin

If Indicatorx crosses over 0 and H[1] > H[2] and O < H[1] then buy next bar at market;

if Indicatorx crosses under 0 and L[1] < L[2] and O > L[1] then sellshort next bar at market;

end;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////


If you want it it tick/tick, then you'll have to turn IOG on [IntraBarOrderGeneration=True] and you'll have to hold the value for the indicator...........

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
[IntraBarOrderGeneration=True]

Variables: Intrabarpersist Indicatorx(0);

indicatatorx = indicatorx;

if marketposition = 0 then begin

If Indicatorx crosses over 0 and H[1] > H[2] and O < H[1] then buy next bar at market;

if Indicatorx crosses under 0 and L[1] < L[2] and O > L[1] then sellshort next bar at market;

end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Reply With Quote
The following user says Thank You to RM99 for this post:



futures io Trading Community Platforms and Indicators EasyLanguage Programming > Coding a simple entry and exit




Upcoming Webinars and Events
 

Free BloodHound Licenses to everyone!

June
 

Every journal equals ten meals for the hungry

June
     



Copyright © 2020 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts