admin管理员组

文章数量:1199521

I wrote a strategy with multiple entries (pyramiding). They should be triggered at different moments. I'm on a 1-minute timeframe.

When the conditions for the first entry is met, I will receive the same alert multiple times.

Multiple entries at the same time

Here is the part of my code that triggers the first entry; Barlastentry is updated after each entry and should prevent 2 entries during the same bar (however, the first entry should happen only once):

//  Execute first entry
if not na (currentPosName) and not firstEntryTriggered and Barlastentry != bar_index
//    splitCapital     := capital / numEntries
    EntryID = "Long_1"
    strategy.entry(EntryID, strategy.long, qty=splitCapital/close, comment= currentPosName+' 1/'+str.tostring(numEntries))
    firstEntryTriggered := true
    currentEntryCount   := 1
    previousEntryPrice  := close
    Bar1stentry         := bar_index
    Barlastentry        := Bar1stentry

Question is: how can I prevent multiple entries at the same time ?

To prevent that, I added some code to avoid multiple entries durin the same Bar. There is no effect.

Of course, if I turn calc_on_every_tick to false, it's working, but I need to leave it to calc_on_every_tick = true.

Thank tou for your help :)

Full code://@version=6
// © JayBen777
// Last updated: 2025-01-18

strategy("Test TV alerts", overlay=true, initial_capital=1000, commission_type = strategymission.percent, commission_value = 0.07, pyramiding = 3, calc_on_every_tick = true, trim_orders = true)

float margeerreur = 0.5/100 // on réduit le capital de 5% pour éviter qu'un ordre ne passe pas sur 3commas
capital          = strategy.initial_capital * (1 - margeerreur)
string Str_Icon  = na

// STRATEGIES
GorillaEnabled    = input.bool(true, 'Gorilla',            group = 'Strategies')

//--- VARIABLES
var bool     firstEntryTriggered  = false
var bool     ttpEnabled           = false
var float    highestPriceSinceTTP = na
var string   currentPosName       = na

// MULTIPLE ENTRIES 
int numEntries         = na    // should be same as strategy Pyramiding
float dropNextEntries  = na  // next entries 
float splitCapital     = na

// PnL
float TTP1Activation    = na     // % profit to activate TTP
float TTP1Deviation     = na     // % trail once TTP is active

// EXIT RULES
bool Step5Enabled = false

bool InPosition = not (strategy.opentrades == 0)

// Entries ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

var float TTP1Price          = na
var float trailingStop       = na
var int Bar1stentry          = na
var Barlastentry             = bar_index
var int currentEntryCount    = 0
var float nextTrigger        = na
var float previousEntryPrice = 0.

//--- 1) First entry

//  Gorilla 

本文标签: pine scriptTradingview Unwanted multiple entries at the same timeStack Overflow