Stuck! How to code simple currency backtest - futures io
futures io futures trading



Stuck! How to code simple currency backtest


Discussion in MultiCharts

Updated by ABCTG
      Top Posters
    1. looks_one radiusvector with 3 posts (0 thanks)
    2. looks_two ABCTG with 3 posts (2 thanks)
    3. looks_3 SMCJB with 1 posts (1 thanks)
    4. looks_4 Al3cs with 1 posts (1 thanks)
    1. trending_up 571 views
    2. thumb_up 4 thanks given
    3. group 5 followers
    1. forum 7 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)

 
Search this Thread
 

Stuck! How to code simple currency backtest

(login for full post details)
  #1 (permalink)
New York City + New York
 
 
Posts: 3 since Dec 2017
Thanks: 4 given, 0 received

Hi,

New to MC + EasyLanguage.

I want to try a simple backtest for EUR/USD, which
- Buys when the current price is just above the previous daily bar's high, and has a fixed stop loss / take profit / break even
- Adjusts position size to be 10% of the total equity in that account per trade

I have intrabar generation as true because I want to buy when the 'current price' of the bar exceeds the previous high. Not the O/H/L/C numbers. Running the code below on the backtest tends to generate way too few trades, only when the daily open is above the previous day's high (even with bar magnifier enabled). Please help!

How can I achieve this? Here's where I stand currently. Thanks in advance!

 
Code
[IntrabarOrderGeneration = True]

vars: Pips(MinMove/PriceScale *10);

condition1 = Open > High[1];
if condition1 then
	Buy ( "8HTT" ) next bar at market ;
setstoploss(Pips * 50);
setprofittarget(Pips * 100);
setbreakeven(Pips * 50);

Reply With Quote

Can you help answer these questions
from other members on futures io?
Macros for flatten and reverse
TradeStation
Degiro Negative Balance Advice
Traders Hideout
QDEL
Stocks and ETFs
I have segregated my investment and trading
Psychology and Money Management
3x Fangdango
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on futures io
VWAP for stock index futures trading?
37 thanks
Coronavirus COVID-19
19 thanks
Battlestations: Show us your trading desks!
13 thanks
VWAP oscillator for NT8
10 thanks
Opinion on iron condor strategy
8 thanks
 
(login for full post details)
  #2 (permalink)
Legendary Market Wizard
Houston, TX
 
Experience: Advanced
Platform: Trading Technologies
Broker: Primary Advantage Futures. Also ED&F and Tradestation
Trading: Primarily Energy but also a little ES, GE, GC, SI & Bitcoin
 
Posts: 3,603 since Dec 2013
Thanks: 2,879 given, 6,773 received

May not answer your question completely but if you replace
 
Code
condition1 = Open > High[1];
if condition1 then
	Buy ( "8HTT" ) next bar at market ;
With
 
Code
Buy ( "8HTT" ) next bar at high stop ;
I think you'll see something similair to what you want.

Your code is looking at the high of bar 1, comparing it to the open of bar 2, and then sending an order on the open of bar 3. Using the stop code, it looks at the high of bar 1, and enters a buy (stop) order to buy immediately if the market equals the high of bar 1 DURING bar 2.

Can't help on position sizing cause I trade futures.

Reply With Quote
The following user says Thank You to SMCJB for this post:
 
(login for full post details)
  #3 (permalink)
Cagliari, Italy
 
Experience: Intermediate
Platform: SC, MC.net, Jigsaw
Broker: AMP+CQG, Directa
Trading: FDAX
 
Posts: 10 since May 2016
Thanks: 18 given, 2 received


The previous days high is HighD(1).
If you use High[1] youre watching at previous candle. It is the same only in daily TF but you can use HighD in every TF and it will always return previous days High.
Notice that HighD is a function and High is an array.
About your entry think about this: do you want a market entry or a breakout entry at HighD[1] + 1 stop ?


Sent from my iPhone using futures.io

Reply With Quote
The following user says Thank You to Al3cs for this post:
 
(login for full post details)
  #4 (permalink)
Hamburg Germany
 
Experience: Advanced
Platform: Multicharts, Tradestation
Broker: DTN IQ
Trading: ES
 
Posts: 2,197 since Apr 2013
Thanks: 386 given, 1,432 received

radiusvector,

are you applying the code to a daily chart or an intraday chart?



radiusvector View Post
Hi,
Running the code below on the backtest tends to generate way too few trades, only when the daily open is above the previous day's high (even with bar magnifier enabled).

Your code tells MC to do exactly what you are seeing as you are using the reserved word "Open", which just returns the open of the bar and does not change during the bar. The reserved word Close on the other hand will get updated throughout the bar and return the last traded price.
As @SMCJB and @Al3cs have pointed out the correct approach will depend whether you want to issue a market order when your condition is met or place a stop order upfront at the desired entry price.

Regards,

ABCTG

Follow me on Twitter Visit my Facebook Reply With Quote
The following user says Thank You to ABCTG for this post:
 
(login for full post details)
  #5 (permalink)
New York City + New York
 
 
Posts: 3 since Dec 2017
Thanks: 4 given, 0 received

So helpful! Thanks so much

Switching to

 
Code
condition1 = Close > High[1];
if (condition1 and MarketPosition = 0) then
	Buy ( "8HTT" ) next bar at market ;
Got it to do exactly what was needed. I wanted the flexibility of testing on multiple timeframes so went with High[1] rather than HighD, but appreciate the suggestion.

Any ideas on how to get started on the position sizing?

Right now, trading 1 contract (and no leverage settings) seems to be tiny and I am trying to get it to trade 10% of the equity on my account. I'm also assuming that leverage will be calculated in my algo rather than an MC setting.

Reply With Quote
 
(login for full post details)
  #6 (permalink)
Hamburg Germany
 
Experience: Advanced
Platform: Multicharts, Tradestation
Broker: DTN IQ
Trading: ES
 
Posts: 2,197 since Apr 2013
Thanks: 386 given, 1,432 received

radiusvector,

for your backtests it might be simpler to create an input allowing you to specify the start account equity and then
size your position based on that (maybe store the starting equity in a variable and add the NetProfit to keep track of the changes in the account equity).
The actual formula for the sizing depends on your broker as some deal in units and others in lots.

Regards,

ABCTG

Follow me on Twitter Visit my Facebook Reply With Quote
The following user says Thank You to ABCTG for this post:
 
(login for full post details)
  #7 (permalink)
New York City + New York
 
 
Posts: 3 since Dec 2017
Thanks: 4 given, 0 received


ABCTG View Post
radiusvector,

for your backtests it might be simpler to create an input allowing you to specify the start account equity and then
size your position based on that (maybe store the starting equity in a variable and add the NetProfit to keep track of the changes in the account equity).
The actual formula for the sizing depends on your broker as some deal in units and others in lots.

Regards,

ABCTG

Thanks ABCTG, here's what I came up with but it tends to buy the same amount of units each trade. What am I doing wrong?

 
Code
[IntrabarOrderGeneration = True]

inputs: start$(100000), riskpct(1), lev(50);

vars: Pips(MinMove/PriceScale *10), Equity (0), Amt (0); 

condition1 = Close > High[1];
if (condition1 and MarketPosition = 0) then
	Equity = start$ + NetProfit;
	Amt = Equity * riskpct * 0.01 * lev;
	Buy ( "Buy" ) Amt contracts next bar at market ;

setstoploss(Pips * 50);
setprofittarget(Pips * 100);
setbreakeven(Pips * 50);

Reply With Quote
 
(login for full post details)
  #8 (permalink)
Hamburg Germany
 
Experience: Advanced
Platform: Multicharts, Tradestation
Broker: DTN IQ
Trading: ES
 
Posts: 2,197 since Apr 2013
Thanks: 386 given, 1,432 received

radiusvector,

I would suggest to use the print reserved word to keep track of the values that your code sees and what you compute internally.
Besides that, if you want to include more than one expression in your conditions, you will have to use "if... then begin...end" statements. https://www.multicharts.com/trading-software/index.php/If

Regards,

ABCTG

Follow me on Twitter Visit my Facebook Reply With Quote


futures io Trading Community Platforms and Indicators MultiCharts > Stuck! How to code simple currency backtest


December 5, 2017


Upcoming Webinars and Events
 

An Afternoon With futures io member TropicalTrader

Elite only
     



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