[cmd] GetPID (getPositionId)

stable
By Strooth in Miscellaneous Published November 2021 👁 1,464 views 💬 1 comments

Description

---Usage for i=1, 100 do local LongPosId = CC_getPID(true, k) local ShortPosId = CC_getPID(false, k) do blah with LongPosId do blah with ShortPosId end
HaasScript
-- Author: Strooth
DefineCommand('getPID', 'Get the positionId for the index and side (PositionLong or PositionShort')
local isLong = DefineParameter(DynamicType, 'isLong', 'Accepts either boolean true = long, false = short or enum PositionLong, enum PositionShort', true, '', 'true/false/PositionLong/PositionShort')
local index = DefineParameter(NumberType, 'Index', 'The number/index of the position', false, 1, 'Number')
local save = DefineParameter(BooleanType, 'Save', 'Force a save of the positionid to update manually', false, false, 'true/false')
if And(isLong != '', isLong != true, isLong != false) then 
    isLong = IfElseIf(isLong == PositionLong, isLong == PositionShort, true, false, 0)
    if isLong == 0 then 
        LogError('getPID command - inccorrect paramerter for isLong. Please specify true/false or PositionLong/PositionShort')
        return 
    end 
end 
local getPID = function(isLong, index, save) 
    local pid = NewGuid()
    if save then 
            if isLong then Save(index..'longid', save)
            else Save(index..'shortid', save) end 
    else 
        if isLong then 
            pid = CC_CheckPositionId(Load(index..'longid', NewGuid()))
            Save(index..'longid', pid)
        elseif not isLong then 
            pid = CC_CheckPositionId(Load(index..'shortid', NewGuid()))
            Save(index..'shortid', pid)
        end
        return pid 
    end 
end

DefineOutput(DynamicType, getPID(isLong, index, save), 'The pid for the position index and side', 'String, DynamicType')

1 Comment

Sign in to leave a comment.

S
SerumScalperStale about 3 years ago

Where to paste this script in Signal trigger?