Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © Maurizio-Ciullo
- // https://www.youtube.com/watch?v=b3PaVZkDbDI&t=808s
- //@version=5
- indicator("38 Lezione Personale 1 How To Debug Pine Script")
- plot(close)
- // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // Create debugging values // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- float averageVolume = ta.sma(volume, 50) // Media volume 50 candele
- bool raisedVolume = volume > averageVolume // Volume ultima barra > averageVolume
- // plot(raisedVolume) // Qui avrò un errore perchè non posso plottare un buleano
- // Nell'esempio sotto "che va bene", però se avessimo un plot di valore molto basso
- // pine andrebbe a fare lo scaling a partire dal quel valore fino al valore attuale
- // plot(raisedVolume ? 1 : 0, title="Raised Volume")
- // in questo modo, con plotchar evitiamo lo scaling
- plotchar(raisedVolume ? 1 : 0, title="Raised Volume", text=" ", color=color.new(color.red, 100))
- bgcolor(raisedVolume ? color.new(color.red, 50) : na) // Imposto il background. Per far funionare il color devo eliminare il color iniziale
- // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // Altro esempio per vedere le differenze dello scaling e no scaling // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- // Displaying Data In The Data Window
- // Plot works but preferred option is plotchar (as it will not affect chart scale)
- plotchar(averageVolume, title="Raised Volume", color=color.new(color.red, 100))
- plotchar(volume, title="Current Volume", color=color.new(color.red, 100))
- // Plotchar Example With A very Low Value As Example (1)
- plot(1, title="Average Volume", color=color.new(color.red, 100))
- plotchar(1, title="Average Volume", text=" ", color=color.new(color.red, 100))
- // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // Per Il For Loop Le Cose Diventano Più Complicate // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- // Con il foor loop non posso usare qualsiasi plot in local scope
- // for i = 0 to 10 // Il conteggio in questo modo sarà di 11 barre compreso lo 0
- // plotchar(volume[i], text=" ", color=color.new(color.red, 100))
- // Ottengo il bar size delle ultime 10 barre high - low
- float totalBarSize = 0.0
- for i = 0 to 9
- totalBarSize := totalBarSize + (high[i] - low[i])
- plotchar(totalBarSize, title="Total Bar Size", text=" ", color=color.new(color.red, 100))
- // Ottengo la media bar size delle ultime 10 barre high - low
- float averageBarSize = totalBarSize / 10
- plotchar(averageBarSize, title="Average 10 Bar Size", text=" ", color=color.new(color.red, 100))
- // Ora uniamo il tutto con un'input
- int loopLenght = input.int(title="loopLenght", defval=10, minval=1)
- float totalBarSize2 = 0.0
- for i = 0 to loopLenght -1 // Meno 1 perchè include lo 0
- totalBarSize2 := totalBarSize2 + (high[i] - low[i])
- float averageBarSize2 = totalBarSize2 / loopLenght
- plotchar(averageBarSize2, title="Average 10 Bar Size 2", text=" ", color=color.new(color.red, 100))
- plotchar(loopLenght, title="Loop Back Lenght", text=" ", color=color.new(color.red, 100))
- // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // Fare Il Debug Con Le String Text Creando Delle Labels // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- // Si potrebbe anche creare un'array, inserire ogni singolo valore nell'array e usare plotchar per plottare i risultati ma con le labels si fa prima
- string debugString = "" // Creo una string vuota
- float totalBarSize3 = 0.0
- for i = 0 to loopLenght -1 // Meno 1 perchè include lo 0
- totalBarSize3 := totalBarSize3 + (high[i] - low[i]) // Restituisce la size delle barre che si sommano man mano fino a loopLenght
- //debugString := debugString + "[" + str.tostring(i) + "]" + "\n" // Assegno alla stringa il loop convertito in stringa e vado a capo con "\n"
- // Aggiungo i valori che mi servono ai valori del loop della riga sopra
- debugString := debugString + "[" + str.tostring(i) + "] TotalBarSize " + str.tostring(totalBarSize3) + //"\n"
- " Bar Size= " + str.tostring(high[i] - low[i]) + "\n" // This line can be added on the same line or below creating a new line with 1ne more spase after indentation
- // Per verificare se è tutto ok misurale la differenza tra massimo e minimo dell'ultima candela e sommarla alla differenza massimo e minimo della candela/e precedenti
- if barstate.islast
- label.new(bar_index, high, debugString, text="debugString", color=color.black, textcolor = color.white, textalign = text.align_left)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement