Retrun variable into main

  • Estado: Closed
  • Premio: $20
  • Propuestas recibidas: 3
  • Ganador: laxmikw

Resumen del concurso

The following Program works well. However the variable "result" needs to be accessable from outside of "tulind.indicators.sma.indicator([close], [3], function(err, results) {}".
extend the code below that the value of "result is accessable outside of "tulind.indicators.sma.indicator([close], [3], function(err, results) {}"

Update:
To be clear,- the var needs to be go into a global "this.smaExample" to have to possibility to pass this Var later on into other functions.


var tulind = require('tulind');
//Examples assume you have some price data like this:
var close = [4,5,6,6,6,5,5,5,6,4];

//Do a simple moving average on close prices with period of 3.
tulind.indicators.sma.indicator([close], [3], function(err, results) {
console.log("Result of sma is:");
console.log(results[0]);
});





To make this once more more clear:

var tulind = require('tulind');
var _ = require('lodash');

calculate_mytulip = function(params,cb) {
if ( params.indicator === "sma" || params.indicator === "ema"){
tulind.indicators[params.indicator].indicator([params.candleArr.close], [params.period], function(err, results) {
cb({success:true,data:results});
});
}
}

async function async_calculate_mytulip(params){
return new Promise((resolve,reject)=>{
calculate_mytulip(params,function(res){
resolve(res);
})
})
}

method = {}
method.check = async function() {
this.indicators = {
sma20: {},
ema20: {},
}
var envelop = {
indicators: {
ema20: {
name: "ema",
period: 20, // should be an aray later on for another loop inside the each
},
sma20: {
name: "sma",
period: 20, // should be an aray later on for another loop inside the each
},
},
candleArr: {close: [4,5,6,6,6,5,5,5,6,4]},
period: 20,
}

_.each(envelop.indicators, function(params, indicator) {
var answer = async_calculate_mytulip(envelop)
console.log("DEBUG: HERE I NEED THE RESULTS! Result of", indicator, " is:");
console.log(answer)
this.indicators[indicator] = answer;
},this)

console.log("DEBUG: and finnaly it should be here usable:",this.indicators.sma20)
console.log("DEBUG: and here:",this.indicators.ema20)
}


// just for a ogiginal representing of the real environment, please ignore!!!
var main = function(callback) {
callback('get it?');
};

main(method.check);

//-------------------------------------------------------------------------------
// However the results are:
// DEBUG: HERE I NEED THE RESULTS! Result of ema20 is:
// Promise { <pending> }
// DEBUG: HERE I NEED THE RESULTS! Result of sma20 is:
// Promise { <pending> }
// DEBUG: and finnaly it should be here usable: Promise { <pending> }
// DEBUG: and here: Promise { <pending> }

Habilidades recomendadas

Comentarios del empleador

“Great supporter, She was understanding the problematic and developt quick and pricise. Also corrections were done fast and good. I would hire here again !!!!”

Imagen del perfil haxus, Germany.

Principales propuestas de este concurso

Ver más participaciones

Tablero de aclaración pública

  • laxmikw
    laxmikw
    • 5 años atrás

    I have done it.

    • 5 años atrás
    1. laxmikw
      laxmikw
      • 5 años atrás

      Please check entry #4

      • 5 años atrás

Cómo comenzar con los concursos

  • Publica tu concurso

    Publica tu concurso Fácil y rápido

  • Recibe montones de propuestas

    Consigue toneladas de propuestas De todo el mundo

  • Elige la mejor propuesta

    Elige la mejor propuesta ¡Descarga fácilmente los archivos!

Publica un concurso ahora o únete a nosotros hoy