CMD - Plot Average EnterPrice

stable
By Strooth in Miscellaneous Published March 2021 👁 1,169 views 💬 0 comments

Description

Note - Requried custom command: GetColor Grabbed this originally from pshai's work but I have since modified it and made it into a cmd that I can call on any script easily Option 1 - just give it the position id and thats it!

-- Plot
         InputGroupHeader('Average Enter Price')
         Finalize(CC_PlotAEP(longPosId))
         Finalize(CC_PlotAEP(shortPosId))
Option 2 - If you as using it more then once to plot multiple positions then you can specify suffix, input name and color

-- Plot
         InputGroupHeader('Average Enter Price')
         Finalize(CC_PlotAEP(longPosId, 'Trade', 'Long Trade', 'DarkGreen'))
         Finalize(CC_PlotAEP(shortPosId, 'Trade', 'Short Trade', 'Maroon'))
HaasScript
DefineCommand('PlotAEP', 'Average Enter Price')
local paep = {
pposId = DefineParameter(DynamicType, 'paep.pposId', 'The long positionId', true, 0, 'Number, Input'),
suffix = DefineParameter(StringType, 'paep.suffix', 'The suffix to use in the paep.name of the line', false, '1', 'String, Input'),
pcolor = CC_GetColor('Teal', DefineParameter(StringType, 'paep.pname', 'The input name if using more then once', false, 'AvgEP', 'Number, Input'), DefineParameter(StringType, 'paep.pcolor', 'The Color of the line', false, 'none', 'string')),
}

paep.aep= GetPositionEnterPrice(paep.pposId)
paep.isLong = GetPositionDirection(paep.pposId) == PositionLong and true or false 
paep.chartname = StringJoin('Average Enter Price ', paep.suffix, '-')
paep.name = paep.isLong and StringJoin('AvgEP Long ', StringJoin(' ',paep.suffix), '-') or StringJoin('AvgEP Short ', StringJoin(' ',paep.suffix), '-')
paep.params = {c=paep.pcolor, id=paep.pposId, w=2}

if paep.aep> 0 and paep.isLong then
    Plot(0, paep.name, paep.aep, paep.params)
    ChartSetOptions(0, paep.chartname)
elseif paep.aep> 0 and paep.isLong == false then
    Plot(0, paep.name, paep.aep, paep.params)
    ChartSetOptions(0, paep.chartname)
end
 
DefineOutput(VoidType)

0 Comments

Sign in to leave a comment.

No comments yet. Be the first!