Where is the mistake? - futures io
futures io



Where is the mistake?


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one kevinkdog with 1 posts (1 thanks)
    2. looks_two ShadowFox with 1 posts (1 thanks)
    3. looks_3 SMCJB with 1 posts (2 thanks)
    4. looks_4 JBroex with 1 posts (0 thanks)
    1. trending_up 3,483 views
    2. thumb_up 4 thanks given
    3. group 3 followers
    1. forum 3 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)

 
Search this Thread
 

Where is the mistake?

(login for full post details)
  #1 (permalink)
JBroex
Istanbul
 
 
Posts: 35 since Sep 2020
Thanks: 24 given, 19 received

Hi everyone,

I create the following code (see below), but my stop loss doesnt seem to work at some instances (both for the "stop l" and the "Stop&rev 1". Any idea why?

Thanks!

 
Code
//Determine current and target profit
TargetProfit = highest(close,MAlen) - lowest(close,MALen);
CurrentProfit = Close - Entryprice(1);

//Define entry
If ATR < ATRlowest[1] and MADiff < EntryAmount then  buy next bar at market;

//Define exit - if initilal is buy
If barssinceentry < 100 AND MarketPosition = 1 AND CurrentProfit < -stopamount then sellshort ("Stop&rev l") next bar at market;
If Currentprofit > TargetProfit then sell ("Long target hit 1") next bar at market;

If barssinceentry > 100 AND MarketPosition = 1 AND CurrentProfit < -stopamount then sell ("Stop l") next bar at market;
If Currentprofit > TargetProfit then sell ("Long target hit 2") next bar at market;

//Define exit - if intial is sell
If MarketPosition = -1 AND CurrentProfit < -stopamount then buy ("Stop&rev  s") next bar at market;
If Currentprofit > TargetProfit then buytocover ("Short targe hit") next bar at market;

Reply With Quote

Can you help answer these questions
from other members on futures io?
How do I create Strategy with the Second Entry indicator
NinjaTrader
in depth understanding of last, bid, and ask volume in c …
NinjaTrader
NT8 Order Management Strategy
The Elite Circle
help with take profit several targets
TradeStation
Market on Close data within IB
Platforms and Indicators
 
 
(login for full post details)
  #2 (permalink)
 SMCJB 
Legendary Market Wizard
Normally Houston TX but currently travelling a lot
 
Experience: Advanced
Platform: TT and Stellar
Broker: Primary Advantage Futures. Also ED&F and Tradestation
Trading: Primarily Energy but also a little Equities, Fixed Income, Metals and Crypto.
 
Posts: 4,747 since Dec 2013
Thanks: 4,063 given, 9,563 received

Not an expert, but I will point out that Tradestation runs code at the end of the bar, for action on the next bar. Since your stops are dependent upon you having a position (you use marketposition to check this) the bar that you enter your position, you will have no stop for that bar as marketposition was different at end of the previous bar. You can get around this by creating your own tracker variable to monitor your position and when you create a new order, update the variable.

ie
 
Code
//Update Variable
If marketposition > 0 then WeAreLong = 1 else WeAreLong = 0

//Define entry
If ATR < ATRlowest[1] and MADiff < EntryAmount then begin
 buy next bar at market;
 WeAreLong = 1 // This tells the code, you will be long next bar, hence make sure you have a stop
End;

//Define exit - if initilal is buy
If barssinceentry < 100 AND WeAreLong = 1 AND ..... // replace marketposition = 1 with WeAreLong = 1

Reply With Quote
The following 2 users say Thank You to SMCJB for this post:
 
(login for full post details)
  #3 (permalink)
 ShadowFox 
CO/USA
 
Experience: Intermediate
Platform: TradeStation, Multicharts
Trading: Stocks, Futures
 
ShadowFox's Avatar
 
Posts: 116 since Jun 2020
Thanks: 69 given, 156 received


It's possible the Entryprice(1) is the culprit. Entryprice(0) is your current position entry. Entryprice(1) is your previous position. Looks like most of the logic is expecting more than one bar to hit stops or targets so you may not need intrabar order generation but that may be a good thing to check if you are expecting some fills in the same bar. I can see that being detrimental to this strategy though.

Visit my futures io Trade Journal Reply With Quote
The following user says Thank You to ShadowFox for this post:
 
(login for full post details)
  #4 (permalink)
 kevinkdog   is a Vendor
 
 
Posts: 3,465 since Jul 2012
Thanks: 1,827 given, 6,985 received

Instead of CurrentProfit, I'd use OpenPositionProfit, which is a reserved word.

There may be cases where your calculation of CurrentProfit is incorrect, due to flipping of positions, etc.

Follow me on Twitter Reply With Quote
The following user says Thank You to kevinkdog for this post:


futures io Trading Community Platforms and Indicators EasyLanguage Programming > Where is the mistake?


Last Updated on February 22, 2021


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
     



Copyright © 2023 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada), 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