Position size variable to calculate £ per point

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #123041 quote
    LG Mcgavin
    Participant
    Junior
    Equity=10000
    Risk=0.01
    
    //Position size
    Positionsize= round(Equity*Risk)/SL //** SL should be the number of pips i.e the variable based on the entry price and stop to calculate the £ per pip based on the equity and risk. **** //appreciate any thoughts on this.
    
    ///Stop Loss
    HH = Highest [5] (high)+2
    SL = HH - TradePrice ////Returns the number of pips between entry price and Higher High to set stoploss at prev high
    If ShortOnMarket then
    Set stop ploss SL ///stop loss set at prev high based on SL
    endif
    

    Hi all, I am very new to PRT coding. I am struggling with the ‘position size’. This is based on the equity of 10,000 and risk of 0.01, giving the max risk per trade. The variable is the number of pips between the entry pice and the stop.

    I would like to divide the max risk per trade by the variable to calculate the £’s per point .
    However the formula i have written PRT does not seem to be returning a variable for the position size.

    Positionsize= round(Equity*Risk)/SL

    Appreciate any thoughts on this. Thank you and please find code attached.

    #123056 quote
    Vonasi
    Moderator
    Master

    LG Mcgavin – Welcome to the forums. Your topic is strategy related and not indicator related so you posted it in the wrong forum. I have moved it to the ProOrder forum. Please try to post in the correct forum with any future topics.

    #123097 quote
    LG Mcgavin
    Participant
    Junior

    Hi Vonasi,

    Thank you and my apologies.

    #123123 quote
    Vonasi
    Moderator
    Master

    You can’t use TRADEPRICE in a calculation for position size. TRADEPRICE returns the price of the last trade whether that is opening a position or closing a position. You can’t know an opening price until you actually have opened a position. You should use CLOSE to calculate your position size and hope that there is not a massive gap to the open of the next candle when your order will actually be filled and then TRADEPRICE updated.

    Also in your code you calculate using SL before SL has a value so on the first run through the code you are dividing by zero.

    LG Mcgavin thanked this post
    #123155 quote
    AutoStrategist
    Participant
    Veteran

    I wrote the code below a couple of years ago based on a Van Tharp blog, I had it in a number of my strategies but I no longer use it, hopefully someone can make use of it.  I extended it to do prices in .25 increments, no idea what the constant TF does it came from the original.

    equity = 10000+STRATEGYPROFIT
    risk=0.025
    
    TF=4
    //
    if OpenDayofWeek = 0 then
    //OkToTrade = 0
    elsif OpenDayofWeek = 1 then // Monday
    DailyRange=max(abs(Dhigh(2)-Dlow(2)),max(abs(Dhigh(2)-Dclose(3)),abs(Dlow(2)-Dclose(3))))
    elsif OpenDayofWeek = 2 then // Tuesday
    DailyRange=max(abs(Dhigh(1)-Dlow(1)),max(abs(Dhigh(1)-Dclose(3)),abs(Dlow(1)-Dclose(3))))
    else
    DailyRange=max(abs(Dhigh(1)-Dlow(1)),max(abs(Dhigh(1)-Dclose(2)),abs(Dlow(1)-Dclose(2))))
    endif
    DailyRange=max(abs(Dhigh(0)-Dlow(0)),DailyRange)
    
    DailyATR=wilderaverage[20*TF](DailyRange)
    a = (equity*risk)/(DailyATR)
    t = a * 100
    x = 0
    // .25 decimal position sizes
    incrementsize = 25
    while x < t do
    x = x + incrementsize
    if x > t then
    if x - t > incrementsize/2 then
    x = x - incrementsize
    endif
    PositionSize = (x/100)
    break
    endif
    wend
    
    MaxStopValue = round(equity*risk)
    LG Mcgavin and Nicolas thanked this post
    #123230 quote
    LG Mcgavin
    Participant
    Junior

    Thank you Vonasi that explains why PRT is not returning a value. Auto Strategist thank you for the code above to reference. Cheers!

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

Position size variable to calculate £ per point


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
LG Mcgavin @lg_mcgavin Participant
Summary

This topic contains 5 replies,
has 3 voices, and was last updated by LG Mcgavin
5 years, 11 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 03/23/2020
Status: Active
Attachments: No files
Logo Logo
Loading...