Coding a simple entry and exit - EasyLanguage Programming | futures io social day trading
futures io futures trading


Coding a simple entry and exit
Updated: Views / Replies:7,780 / 10
Created: by johni Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

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

Reply
 
Thread Tools Search this Thread
 

Coding a simple entry and exit

  #1 (permalink)
Trading Apprentice
canada
 
Futures Experience: Master
Platform: ts
Favorite Futures: stock
 
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
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
 Vendor: tradingcode.net 
The Netherlands
 
Futures Experience: None
Platform: MultiCharts, TradingView
Favorite Futures: ...
 
Jura's Avatar
 
Posts: 774 since Apr 2010
Thanks: 2,347 given, 661 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 user says Thank You to Jura for this post:
 
  #4 (permalink)
Fortitudo et Honor
Austin, TX
 
Futures Experience: Advanced
Platform: TradeStation
Favorite Futures: Futures
 
Posts: 882 since Mar 2011
Thanks: 128 given, 703 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)
Trading Apprentice
canada
 
Futures Experience: Master
Platform: ts
Favorite Futures: stock
 
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)
 Vendor: tradingcode.net 
The Netherlands
 
Futures Experience: None
Platform: MultiCharts, TradingView
Favorite Futures: ...
 
Jura's Avatar
 
Posts: 774 since Apr 2010
Thanks: 2,347 given, 661 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)
Trading Apprentice
canada
 
Futures Experience: Master
Platform: ts
Favorite Futures: stock
 
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)
Fortitudo et Honor
Austin, TX
 
Futures Experience: Advanced
Platform: TradeStation
Favorite Futures: Futures
 
Posts: 882 since Mar 2011
Thanks: 128 given, 703 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)
Trading Apprentice
canada
 
Futures Experience: Master
Platform: ts
Favorite Futures: stock
 
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)
Fortitudo et Honor
Austin, TX
 
Futures Experience: Advanced
Platform: TradeStation
Favorite Futures: Futures
 
Posts: 882 since Mar 2011
Thanks: 128 given, 703 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:

Reply



futures io > > > > > Coding a simple entry and exit

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Combined auto-entry and manual-exit strategy as a money management device nanobiotech Psychology and Money Management 10 January 31st, 2015 08:51 AM
Strategy Entry/Exit Visualization zeller4 NinjaTrader Programming 6 November 8th, 2012 11:22 AM
a simple entry exit bar johni EasyLanguage Programming 7 July 23rd, 2011 05:34 AM
1 entry order 5 exit orders togier Traders Hideout 2 April 11th, 2011 04:27 AM
Rooky questionning, Coding a conditionnal entry + a stop loss if done arjfca EasyLanguage Programming 7 December 13th, 2010 04:10 PM


All times are GMT -4. The time now is 07:19 AM.

Copyright © 2017 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
Page generated 2017-12-13 in 0.13 seconds with 19 queries on phoenix via your IP 54.196.182.102