Simple Standard Deviation Entries

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
User avatar
pivot
Posts: 29
Joined: 07 Dec 2009
Been thanked: 2 times

Simple Standard Deviation Entries

Postby pivot » 26 Jul 2011

I am trying to write some code for simple Standard Deviation Entries. This would be on current bar +/- X SD there would be Long limit order and a short limit order on the current bar


Here is the code I have written code someone with more coding skills then me take a look and help me to correct this as I am not sure what I am missing.

Code: Select all

Inputs:
SDLen (100),
NSD ( 2 );
   
Variables:
vSDEnt(0);
           
vSDEnt = StandardDev( c, SDLen, 2 );

{ Variables for entry and exit prices } 
Value1 = vSDEnt * NSD;
 
variables:   
vMP (0),
EntPrL (0),
EntPrS (0);

vMP = marketposition;
EntPrL = c[1] - value1;
EntPrS = c[1] + value1;

if currentbar >2 and vMP = 0 then
begin
    Buy currentbar at EntPrL Limit;
    and
    Sellshort Currentbar at EntPrS limit;
end;


Thanks in Advance

User avatar
JoshM
Posts: 2089
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1525 times
Been thanked: 1485 times
Contact:

Re: Simple Standard Deviation Entries

Postby JoshM » 26 Jul 2011

Hi Pivot,

Looks good, though there is one logical error in it (in my opinion). You enter a position with a EntPrL limit or EntPrS limit price, that you want to have submitted at the current bar. However, these limit prices are calculated using the vSDEnt variable, which holds the StdDev value for the *current* bar. Since the (true) closing value is only known at the end of the bar, submitting a limit order using that value during a bar might introduce a error in your strategy.

Perhaps something like this might work:

Code: Select all

Inputs: SDLen (100),
    NSD ( 2 );
   
Variables: vSDEnt(0),
   vMP(0),
   EntPrL(0),
   EntPrS(0);

vSDEnt = StandardDev( c, SDLen, 2 );
Value1 = vSDEnt * NSD;
vMP = marketposition;
         
EntPrL = c[1] - value1;
EntPrS = c[1] + value1;

if vMP = 0 then begin
   Buy next bar at EntPrL limit;
   Sellshort next bar at EntPrS limit;
end;

User avatar
pivot
Posts: 29
Joined: 07 Dec 2009
Been thanked: 2 times

Re: Simple Standard Deviation Entries

Postby pivot » 26 Jul 2011

Thanks JoshM -

I want to enter the current bar so would the logic be corrected if in the SD calculation I change it to c[1] reference the previous bars close to calculate SD. Something like this

Code: Select all

vSDEnt = StandardDev( c[1], SDLen, 2 );



but I still can't get it to compile and there are still errors.

I want to have orders placed on current bar and not the next bar. Next bar really changes my logic.

Thanks in advance for your help.

User avatar
TJ
Posts: 6584
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 970 times
Been thanked: 1907 times

Re: Simple Standard Deviation Entries

Postby TJ » 26 Jul 2011

pivot wrote:I am trying to write some code for simple Standard Deviation Entries. This would be on current bar +/- X SD there would be Long limit order and a short limit order on the current bar


Here is the code I have written code someone with more coding skills then me take a look and help me to correct this as I am not sure what I am missing.

Code: Select all

Inputs:
SDLen (100),
NSD ( 2 );
   
Variables:
vSDEnt(0);
           
vSDEnt = StandardDev( c, SDLen, 2 );

{ Variables for entry and exit prices } 
Value1 = vSDEnt * NSD;
 
variables:   
vMP (0),
EntPrL (0),
EntPrS (0);

vMP = marketposition;
EntPrL = c[1] - value1;
EntPrS = c[1] + value1;

if currentbar >2 and vMP = 0 then
begin
    Buy currentbar at EntPrL Limit;
    and
    Sellshort Currentbar at EntPrS limit;
end;


Thanks in Advance


1. you cannot buy at current bar, only at next bar.

2. look up IntraBarOrderGeneration

3. You have an extraneous "and" in between the buy and sell orders.

4. wrong application of the keyword "currentbar". Please look up the keyword dictionary for definition and usage example.

5. Go through the examples in these ebooks would help:
Getting Started with EasyLanguage
The essential EasyLanguage programming guide

User avatar
pivot
Posts: 29
Joined: 07 Dec 2009
Been thanked: 2 times

Re: Simple Standard Deviation Entries

Postby pivot » 26 Jul 2011

Thanks TJ

is it possible to refer calculations on Data2 and then executing on data series 1?

This could be a work around for my logic.

regards

p

User avatar
TJ
Posts: 6584
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 970 times
Been thanked: 1907 times

Re: Simple Standard Deviation Entries

Postby TJ » 26 Jul 2011

pivot wrote:Thanks TJ

is it possible to refer calculations on Data2 and then executing on data series 1?

This could be a work around for my logic.

regards

p



Please read point #5 in post #4 above


Please also read post #4 here:
viewtopic.php?f=16&t=6929

User avatar
furytrader
Posts: 353
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 154 times
Been thanked: 215 times

Re: Simple Standard Deviation Entries

Postby furytrader » 29 Jul 2011

I think your best bet is to try intrabarordergeneration


Return to “User Contributed Studies and Indicator Library”