How to enter only when spread is within certain range

Questions about MultiCharts and user contributed studies.
illumintai
Posts: 5
Joined: 05 Oct 2014

How to enter only when spread is within certain range

Postby illumintai » 09 Oct 2018

Hi,

Apologies for my beginner question. I have a very simple moving average strategy

Code: Select all

inputs: Price( Close ), FastLength( 5 ), SlowLength( 10 ) ;
variables: var0( 0 ), var1( 0 ) ;

var0 = AverageFC( Price, FastLength ) ;
var1 = AverageFC( Price, SlowLength ) ;

condition1 = CurrentBar > 1 and var0 crosses over var1 ;
condition2 = CurrentBar > 1 and var1 crosses over var0 ;

if condition1 then
Buy ( "Go long" ) next bar 10 contract at market ;
if condition2 then
Sell ( "Long exit" ) next bar 10 contract at market ;
What I really want to learn to implement is putting another condition to ensure the spread is competitive when putting on the trade.
Would I do something like this?

Code: Select all

spreadcondition = DOM_AskPrice(1)- DOM_BidPrice(1) < 0.0001 #only go long when spread is below a pip

if condition1 and spreadcondition then
Buy ( "Go long" ) next bar 10 contract at market ;
Or can you suggest a better way?

Thanks!

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: How to enter only when spread is within certain range

Postby TJ » 09 Oct 2018

Hi,

Apologies for my beginner question. I have a very simple moving average strategy

. . .

Thanks!

No need to apologize. We all started from the same place.

But usually, we shy away from questions that begin with . . . I have a very simple . . . :lol:
Because the problem is usually more complicated than they appear.

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: How to enter only when spread is within certain range

Postby TJ » 09 Oct 2018

The first step in thinking clearly. (even in a hypothetical situation)

see post #5
viewtopic.php?t=11713

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: How to enter only when spread is within certain range

Postby TJ » 09 Oct 2018

Hi,

. . .

What I really want to learn to implement is putting another condition to ensure the spread is competitive when putting on the trade.
Would I do something like this?

. . .

Thanks!
Yes you are doing it right.


Return to “MultiCharts”