Simple position size calculation using user defined indicator

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #40909 quote
    FTSE101
    Participant
    New

    Hi

    I have created a simple indicator. When a long condition is triggered I want to call up the value of the user defined indicator “2ATR long stop loss indicator”, divide the entry price by this amount, to calculate the position size to use for the trade. “Fund” is a defined amount – for example fund = 10000.  C1 is a simple moving average cross over.

    See code below – but it is not working. Where am I going wrong?

    Thanks for your help.

    IF c1 THEN
    SLprice= POSITIONPRICE - CALL "2ATR long stop loss indicator"
    PositionSize = fund / SLprice
    BUY PositionSize PERPOINT AT MARKET
    ENDIF
    #40950 quote
    gabri
    Participant
    Master

    Which error message you get?

    #40957 quote
    Pepsmile
    Participant
    Veteran
    You can add the function “round” to PositionSize, as  PositionSize = round(fund / SLprice), nethertheless your PositionSize is working without “round”
    I think POSITIONPRICE is only working if an position is really opened.
    Alseo maybe an error into the code : CALL “2ATR long stop loss indicator”, can you show us the code ? (except with an instruction ONCE, it’s recommanded to avoid the call function) 
    Nicolas thanked this post
    #41035 quote
    FTSE101
    Participant
    New

    Hi – I’ve added the code for the indicator below. I’ve put this code in instead of calling up the indicator value and that now works.

    However it is rounding the position size to a whole number – I want it rounded to two decimal places – how can I do that?  So say fund is 100, indicator (2xATR) is 15 I want the position size to be 100/15 (2 decimal places) = 6.67.

    Thanks for your help – I am quite new to this and it seems for every step forward at the moment I need to take ten steps back !

    //Indicator to show the price MINUS a multiple of ATR
    A=20 //number of bars in ATR
    B=2  //multipler of ATR
    C=AverageTrueRange[A](close)*B
    d = close - c
    RETURN d
    
    #41036 quote
    gabri
    Participant
    Master

    Try with:

    PositionSize = round(100*fund / SLprice)/100
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

Simple position size calculation using user defined indicator


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
FTSE101 @ftse101 Participant
Summary

This topic contains 4 replies,
has 3 voices, and was last updated by gabri
8 years, 6 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 07/17/2017
Status: Active
Attachments: No files
Logo Logo
Loading...